Possible Duplicate:
Accessing C# Anonymous Type Objects
Working with C# Anonymous Types
I'm using linq to entities to get id and full name from a table with customers.
public IQueryable RegresaClientesPorEmpresa(int id_emp)
{
var clientes = from c in context.clientes
where c.IDEmpresa == id_emp
select new
{
c.IDCliente,
NomComp = c.Nombres +" "+ c.ApellidoP +" "+ c.ApellidoM
};
return clientes;
}
The result is used as the datasource of a combobox, then when SelectionChangeCommitted is triggered in my combo, I want the selected item to be added to a listbox:
var clientes = operaciones.RegresaClientesPorEmpresa(2);
combo_cliente.DataSource = clientes;
combo_cliente.DisplayMember = "NomComp";
combo_cliente.ValueMember = "IDCliente";
listBox_grupo.DisplayMember = "NomComp";
listBox_grupo.ValueMember = "IDCliente";
private void combo_cliente_SelectionChangeCommitted(object sender, EventArgs e)
{
listBox_grupo.Items.Add(combo_cliente.SelectedItem);
}
Until here everything is fine. Finally I want to get all "IDCliente"'s values from all items added to my listbox, the problem is that I don't know how to do it because every item is an Anonymous data type. Can anyone help me?