My windows Form contains 1 combobox bound to Categories bindingsource, and 1 datagrid bound to Products binding source. When I load the form the combobox shows the first value in the categories table and not the selected value in the Products table, and when I change position in the Products bindingsource I can get the right selectedValue in the combobox (it displays correct values). So My problem is in the first load of combobox items.
My Combo properties:
data source = categorybindingsource
display Member = CategoryName
Value Member = CategoryID
Selected Value = productBindingSource – CategoryID
And here is my code:
NorthwindDataContext dc;
private void Form1_Load(object sender, EventArgs e)
{
dc = new NorthwindDataContext();
productBindingSource.DataSource = dc.Products;
this.categoryIDComboBox.DataSource = dc.Categories;
}
Try to invert the order of initialization of combobox and datagrid