Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!
I need to create a serie of comboboxes at runtime, so I made an array of comboboxes, but when I change one of them (both at runtime or via code), all the others change too... I need them to be separate.
I created other controls and they work properly instead.
I don't understand why if I change one of them (select an item) all the other combobox displays the same item.
Thank you very much, I appreciate any help!

What I have tried:

Dim ListaDiametri(50) As ComboBox
....

For j = 1 To psNC
                    LD(j) = New ComboBox
                    With LD(j)
                        .Name = String.Format("LD{0}", j)
                        .Tag = j
                        .Font = LD0.Font
                        .Width = LD0.Width
                        .Left = toto - LD(j).Width / 2
                        .Top = PSy4A
                        .DataSource = LD0.DataSource
                        AddHandler .KeyPress, AddressOf PassD
                        AddHandler .Enter, AddressOf Diven
                        AddHandler .Leave, AddressOf Camb
                    End With
                    Me.Controls.Add(LD(j))
                    LD(j).BringToFront()
                    LD(j).Text = Fi(j)
next
Posted
Updated 1-Jul-19 5:24am
Comments
Maciej Los 1-Jul-19 16:18pm    
I do not believe. What's the code of [PassD], [Diven] and [Camb] event handlers?

1 solution

With the same data sources AND event handlers, I'd expect they would all behave the same without more discernment.
 
Share this answer
 
Comments
Member 11182870 8-Jul-19 4:40am    
Thank you Gerry, but even without the event handler it happens... anyway, the enter and leave events just change the colours, the keypress act on another texbox. I'd like to use the "j" index to handle the different comboboxes. I also changed the datasource.
But if I change one, the others change too.
Using numericupdown it works...they don't change all together.
Thank you
pdoxtader 9-Jul-19 9:28am    
You're binding them all to the same data source.

I just created a test project with your code and created new handlers for each one using anonymous subs, and I didn't have the problem. It has to be because you have them all bound to the same data source.
Member 11182870 31-Jul-19 4:16am    
Ok, thank you very much, I'll try with different datasource.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900