I am getting the above error when i am trying this code. I tried giving just my code but no use. (It was default)
The error is in cmbProduct_SelectedIndexChanged event.
cmbProduct --> combobox
cmbBrand --> combobox
Global
DataSet dsUpdate = new DataSet();
Form_load
dsUpdate.ReadXml(@"...\..\stock.xml");
cmbProduct.DataSource = dsUpdate.Tables[0]
.DefaultView.ToTable(true, "productname");//.DefaultView;
cmbProduct.DisplayMember = "productname";
cmbProduct.SelectedIndex = 0;
cmbProduct_SelectedIndexChanged
cmbBrand.Items.Clear();
foreach (DataRow Row in dsUpdate.Tables[0].Select("productname='" + cmbProduct.Text + "'"))
{
//cmbBrand.SelectedIndex = i;
cmbBrand.Items.Add(Row["brandname"].ToString());
//i++;
}
cmbBrand.SelectedIndex = 0; /*ERROR*/
Please help
Thanks in Advance.
Problem is:
when you start application, you do not have items in cmbBrand, but cmbProduct fires SelectedIndexChanged.
Try this:
remove SelectedIndexChanged event initialization from Form1.Designer.cs. Try to find following line:
After that, when you populate DataSet with data from xml file, initialize SelectedIndexChanged event: