The class below is the data source for the combo of datagridview:
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public string City { get; set; }
}
The next is the data source for the datagridview:
public class Order
{
public int Id { get; set; }
public int IdCustomer { get; set; }
public DateTime RequestDate { get; set; }
}
For simplicity, I will carry them with fixed values, but similar to my real case:
private void Form1_Load(object sender, EventArgs e)
{
bdsCustomer.DataSource = new List<Customer>
{
new Customer {Id = 1, Name = "Paulo", City = "City A"},
new Customer {Id = 2, Name = "Tatiane", City = "City B"},
new Customer {Id = 3, Name = "Paulo", City = "City C"},
};
bdsOrder.DataSource = new List<Order>
{
new Order {Id = 1, IdCustomer = 1, RequestDate = new DateTime(2015, 8, 25)},
new Order {Id = 2, IdCustomer = 2, RequestDate = new DateTime(2015, 8, 26)},
new Order {Id = 3, IdCustomer = 3, RequestDate = new DateTime(2015, 8, 27)}
};
}
I'll let the field "IdCustomer" in datagridview to display the problem and I'll create a new field with the combo:
Notice in the image that the "IdCustomer" field of the first record is correct and presenting the Id 1:
Now I will select the other "Paul" with the Id 3 and see what happens to the value of IdCustomer:
Even selecting the client with the Id 3, the Id continues 1. You can have 10 clients "Paul", anyone who select the IdCustomer does not change.
What can I do?
I solved the problem, I used the DevExpress grid, is now working perfectly!