r_badris
asked on
combo control in .NET
Hi all,
The following code is behaving as, when i select combo1 the corresponding value in combo2 is also changed i havent implemented any code for selectionchanged event for any of the combo boxes.
kindly provide me feedback for this problem..is this bug or funtionality........?
DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("NM");
for (int i=0;i<5; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = "A" + i.ToString();
dt.Rows.Add(dr);
}
comboBox1.DataSource = dt.DefaultView;
comboBox2.DataSource = dt.DefaultView;
comboBox1.DisplayMember="I D";
comboBox1.ValueMember = "ID";
comboBox2.DisplayMember="N M";
comboBox2.ValueMember = "NM";
Regards,
Badri Narayanan R.
The following code is behaving as, when i select combo1 the corresponding value in combo2 is also changed i havent implemented any code for selectionchanged event for any of the combo boxes.
kindly provide me feedback for this problem..is this bug or funtionality........?
DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("NM");
for (int i=0;i<5; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = "A" + i.ToString();
dt.Rows.Add(dr);
}
comboBox1.DataSource = dt.DefaultView;
comboBox2.DataSource = dt.DefaultView;
comboBox1.DisplayMember="I
comboBox1.ValueMember = "ID";
comboBox2.DisplayMember="N
comboBox2.ValueMember = "NM";
Regards,
Badri Narayanan R.
in order to make your code shorter, you can use DataTable.Copy.
DataTable dt = new DataTable();
DataTable dt_2 = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("NM");
for (int i=0;i<5; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = "A" + i.ToString();
dt.Rows.Add(dr);
}
dt_2 = dt.Copy();
comboBox1.DataSource = dt.DefaultView;
comboBox2.DataSource = dt_2.DefaultView;
comboBox1.DisplayMember="I D";
comboBox1.ValueMember = "ID";
comboBox2.DisplayMember="N M";
comboBox2.ValueMember = "NM";
DataTable dt = new DataTable();
DataTable dt_2 = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("NM");
for (int i=0;i<5; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = "A" + i.ToString();
dt.Rows.Add(dr);
}
dt_2 = dt.Copy();
comboBox1.DataSource = dt.DefaultView;
comboBox2.DataSource = dt_2.DefaultView;
comboBox1.DisplayMember="I
comboBox1.ValueMember = "ID";
comboBox2.DisplayMember="N
comboBox2.ValueMember = "NM";
is this combo in win form or asp .net web page
plz specify
plz specify
to explain what is happening, you have assigned the SAME dataTable to BOTH comboxes. So when the DataTable entry you are pointing to changes in Combo Box1, the same entry in Combox Box 2 will be selected, since it is the same reference in the same DataTable.
If you want the two to act independently, then you will need two, completely independent Data Tables, as suggested by peachapol.
AW
If you want the two to act independently, then you will need two, completely independent Data Tables, as suggested by peachapol.
AW
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Buddies will try out yours options!!! :-)
example
DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("NM");
for (int i=0;i<5; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = "A" + i.ToString();
dt.Rows.Add(dr);
}
DataTable dt_2 = new DataTable();
dt_2.Columns.Add("ID");
dt_2.Columns.Add("NM");
for (int i=0;i<5; i++)
{
dr = dt_2.NewRow();
dr[0] = i;
dr[1] = "A" + i.ToString();
dt_.2Rows.Add(dr);
}
comboBox1.DataSource = dt.DefaultView;
comboBox2.DataSource = dt_2.DefaultView;
comboBox1.DisplayMember="I
comboBox1.ValueMember = "ID";
comboBox2.DisplayMember="N
comboBox2.ValueMember = "NM";