471,350 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

problems with events for dynamically created comboboxes

Hello

I am using VS 2005 with .net 2 with C#. I have a form with a panel in which I am dynamically creating combo boxes. They are all using the same data source.The reason they are dynamically created is because the program does not how many are required. When I change the selected index for any one of the comboboxes they all change to the same selected index. Any ideas ??. I have tried creating the event as a delegete inside the method which creates the control like this:

private void CreateComboBox(vars...)
{
//code to create control
cbxSource.SelectedIndexChanged += delegate
{
//code run by event
}
}

and I have tried creating the event outside the method as

private void CreateComboBox(vars...)
{
//code to create control
cbxSource.SelectedIndexChanged += new EventHandler(cbxSource_SelectedIndexChanged);
}


void cbxSource_SelectedIndexChanged(object sender, EventArgs e)
{
//code to be run
}

Can anyone please help ??
Jul 7 '07 #1
3 1282
kenobewan
4,871 Expert 4TB
They all trigger the same event hence all display the same selectedindex. One to prevent this may be use code to identify that control and only change that one.
Jul 7 '07 #2
Thanks for your response. I thought that might be the case. I setup a group of comboboxes in an array and initialized them on Form_Load. As I needed them I set their attributes and created their own SelectedIndexChanged event. I also created a tool tip for each one so I could see during run time that each combobox was a different control. The events for each combobox are still tied together even though there is a seperate event for each control
Jul 8 '07 #3
kenobewan
4,871 Expert 4TB
Then I assume the solution is to use the array to indentify which selectedindex to change. HTH.
Jul 8 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by blue | last post: by
1 post views Thread by Bishop | last post: by
9 posts views Thread by Erik Frey | last post: by
2 posts views Thread by Nathan Sokalski | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.