I've already checked other posts but still could not fix my probem: I have two forms:
- One that creates clients ( can have multiple phones, addresses and cars)
- A main form which should display each client info.
First of all, is it possible to have a client in each row, and the three combos (phones, addresses, and cars) with each clients info?
For example:
I've got two clients, John and Jack, and I want the rows displayed like this:
0 - John - John.Phones - John.Addresses - John.Cars
1 - Jack - Jack.Phones - Jack.Addresses - Jack.Cars
Also, I don't know what should I pass to my row as argument for the combobox, should I pass the dataSource, Items, or the combo itself? Whatever I pass for the comboboxes, I get:
System.ArgumentException: DatagridViewRowComboBoxCell value is not valid
Here's the actual code.
private DataGridViewRow BuildRow(Cliente cliente)
{
DataGridViewRow row = new DataGridViewRow();
DataGridViewComboBoxCell Autos = new DataGridViewComboBoxCell();
Autos.DataSource = cliente.Autos;
Autos.ValueMember = cliente.Autos[0].ToString();
row.CreateCells(DGCliente, cliente.Codigo.ToString(), cliente.Nombre, Autos);
row.Tag = cliente;
DGCliente.Rows.Add(row);
return row;
}
Client class code: (spanish)
public class Cliente
{
public String Nombre { get; set; }
public Int32 Codigo { get; set; }
public List<Auto> Autos { get; set; }
public List<Direccion> Direcciones { get; set; }
public List<Telefono> Telefonos { get; set; }
public Cliente()
{
this.Direcciones = new List<Direccion>();
this.Telefonos = new List<Telefono>();
this.Autos = new List<Auto>();
}
public Cliente(String Nombre , Int32 Codigo)
{
this.Nombre = Nombre;
this.Codigo = Codigo;
this.Direcciones = new List<Direccion>();
this.Telefonos = new List<Telefono>();
this.Autos = new List<Auto>();
}
public void AgregarTelefono(bool esCelular, String numero, String area)
{
this.Telefonos.Add(new Telefono(esCelular, numero, area));
}
public void AgregarDireccion(string calle, string altura, string localidad, string provincia)
{
this.Direcciones.Add(new Direccion(calle, altura, localidad, provincia));
}
public void AgregarAuto(Auto auto)
{
this.Autos.Add(auto);
}
}