W
Wade
Hi,
I am dynamically creating X number of combo boxes, all bound to the same
data source. However, even though these combo boxes are all seperate
instances with unique names, when I change the value of one at runtime they
all change to reflect the newly selected value (i.e. I have 3 combo boxes, i
change the first one from nothing to "ABC", and the other two combo boxes
also change to "ABC").
Any clue as to why this might be? I've created a SelectedIndexChanged
event, and this event fires for all the combo boxes when just one of the
combo box indexes are changed.
Here's some of the code I use:
// this is what is called X number of times ...
cmb = new QuickComboBox(
"cmbType_" + iControlNum.ToString(),
pnlPoints,
ptControls.X,
ptControls.Y,
185,
20);
cmb.SelectedIndexChanged += new
EventHandler(cmb_SelectedIndexChanged);
if (dsElementTypes != null)
{
cmb.DisplayMember = "elementType";
cmb.ValueMember = "elementTypeID";
cmb.DataSource = dsElementTypes.Tables[0];
}
// here's the event code ...
private void cmb_SelectedIndexChanged(object sender, EventArgs e)
{
ComboBox c = (ComboBox)sender;
MessageBox.Show(c.Name + ":" + c.SelectedValue.ToString());
}
// this is the code for the QuickComboBox ...
public class QuickComboBox : System.Windows.Forms.ComboBox
{
public QuickComboBox(string name, Control oParent, int x, int y, int
w, int h)
{
this.Parent = oParent;
this.Bounds = new Rectangle(x, y, w, h);
this.Name = name;
}
}
I am dynamically creating X number of combo boxes, all bound to the same
data source. However, even though these combo boxes are all seperate
instances with unique names, when I change the value of one at runtime they
all change to reflect the newly selected value (i.e. I have 3 combo boxes, i
change the first one from nothing to "ABC", and the other two combo boxes
also change to "ABC").
Any clue as to why this might be? I've created a SelectedIndexChanged
event, and this event fires for all the combo boxes when just one of the
combo box indexes are changed.
Here's some of the code I use:
// this is what is called X number of times ...
cmb = new QuickComboBox(
"cmbType_" + iControlNum.ToString(),
pnlPoints,
ptControls.X,
ptControls.Y,
185,
20);
cmb.SelectedIndexChanged += new
EventHandler(cmb_SelectedIndexChanged);
if (dsElementTypes != null)
{
cmb.DisplayMember = "elementType";
cmb.ValueMember = "elementTypeID";
cmb.DataSource = dsElementTypes.Tables[0];
}
// here's the event code ...
private void cmb_SelectedIndexChanged(object sender, EventArgs e)
{
ComboBox c = (ComboBox)sender;
MessageBox.Show(c.Name + ":" + c.SelectedValue.ToString());
}
// this is the code for the QuickComboBox ...
public class QuickComboBox : System.Windows.Forms.ComboBox
{
public QuickComboBox(string name, Control oParent, int x, int y, int
w, int h)
{
this.Parent = oParent;
this.Bounds = new Rectangle(x, y, w, h);
this.Name = name;
}
}