I have this issue when i choose a value from any combobox(DropDownStyle: List) it triggers all the selected index changed to every combobox, that would not be a problem but doing step by step all the combos copy the selected index value that i choosed in the combo box that i made the change.
All the comboboxes has their own SelectedIndexChanged event, for example:
Combo1: Combo1_SelectedIndexChanged, Combo2: Combo2_SelectedIndexChanged, .. etc.
The normal behaviour is to select a value in 1 combobox and fill values in the combobox right next to it, i attach code from selectedindexchanged event in combo 1 and 2 in case is need it.
I already tried to delete all the combos and create them again one by one but it keeps happening, even with only 2 comboboxes in the winform.
Thank you so much for everyone who tried to help.(Also sorry if my english is bad)
/*Combobox1*/
private void comboBox11_SelectedIndexChanged_1(object sender, EventArgs e)
{
pDataSet = new DataSet();
pDataSet.Clear();
pDataSet = neProcesos.NeDataSetCajaCr(13, "", "", "", "", "");
comboBox111.DataSource = pDataSet.Tables[0];
comboBox111.DisplayMember = "Description";
comboBox111.ValueMember = "ID";
comboBox111.SelectedIndex = 0;
if (comboBox11.SelectedIndex > 0)
{
pDataSet = new DataSet();
pDataSet.Clear();
pDataSet = neProcesos.NeDataSetCajaCr(14, comboBox11.SelectedValue.ToString(), "", "", "", "");
comboBox111.DataSource = pDataSet.Tables[0];
comboBox111.DisplayMember = "Description";
comboBox111.ValueMember = "ID";
comboBox111.SelectedIndex = 0;
}
}
/*ComboBox2*/
private void comboBox12_SelectedIndexChanged(object sender, EventArgs e)
{
pDataSet = new DataSet();
pDataSet.Clear();
pDataSet = neProcesos.NeDataSetCajaCr(13, "", "", "", "", "");
comboBox121.DataSource = pDataSet.Tables[0];
comboBox121.DisplayMember = "Description";
comboBox121.ValueMember = "ID";
comboBox121.SelectedIndex = 0;
if (comboBox12.SelectedIndex > 0)
{
pDataSet = new DataSet();
pDataSet.Clear();
pDataSet = neProcesos.NeDataSetCajaCr(14, comboBox12.SelectedValue.ToString(), "", "", "", "");
comboBox121.DataSource = pDataSet.Tables[0];
comboBox121.DisplayMember = "Description";
comboBox121.ValueMember = "ID";
comboBox121.SelectedIndex = 0;
}
}
The problem was with the source of the data.
Initially it was
comboBox11.DataSource = pDataSet.Tables[0];
comboBox11.DisplayMember = "Description";
comboBox11.ValueMember = "ID";
comboBox11.SelectedIndex = 0;
comboBox12.DataSource = pDataSet.Tables[0];
comboBox12.DisplayMember = "Description";
comboBox12.ValueMember = "ID";
comboBox12.SelectedIndex = 0;
then i changed it to their own table from the dataset
comboBox11.DataSource = pDataSet.Tables[0];
comboBox11.DisplayMember = "Description";
comboBox11.ValueMember = "ID";
comboBox11.SelectedIndex = 0;
comboBox12.DataSource = pDataSet.Tables[1];
comboBox12.DisplayMember = "Description";
comboBox12.ValueMember = "ID";
comboBox12.SelectedIndex = 0;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.