473,320 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 1353
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

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

Similar topics

6
by: Thomas | last post by:
Hi, I'm having a problem with the dynamically created inputfields in Internet Explorer. The situation is the following: - I have a dynamically created table with a textbox in each Cell. - It...
4
by: blue | last post by:
I have a drop-down list, a radio button list and a submit button. I'm adding these controls to a table and I'm adding the table to a Placeholder. I'm adding it to the Placeholder because I don't...
1
by: Bishop | last post by:
I have a page that generates a grid of controls; at the end of each row is an update button that is dynamically created with an associated click event. The grid changes based on the date selected...
9
by: Erik Frey | last post by:
Hi there, Just curious as to whether there's a clever way to see the events a control/object is firing off, perhaps written out to the debug console. It would be really handy to know which...
3
by: Shawn | last post by:
Hello All, I am trying to raise enter events for a combobox control that I am building dynamically at run time. A user enters a number in a textbox and that many comboboxes are created. I then...
5
by: Chris Lieb | last post by:
I am trying to add an event listener to the keyup event for some text inputs that I am creating dynamically. I have no problems getting it to work in Firefox, but IE just ignores them. I have...
5
by: Amoril | last post by:
I've read quite a few different message on various boards and for some reason I'm still having trouble wrapping my head around this viewstate maintenance and trying to get these dynamically created...
2
by: Nathan Sokalski | last post by:
I have LinkButtons that are dynamically created in one of the PostBack events. They must be created in the PostBack event because one of the variables required to determine which ones to create...
0
by: theleshie | last post by:
Hi, I am creating an application which dynamically creates forms depending on the information held in a dataset (which also includes the data the application itself uses). As part of dynamically...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.