How to fill the list of one combo box to another combo box?
-
I have a form which is having two combo boxes. This two combo boxes contains the same list. This list is retrieved from the database. First, I am filling the first combo box and then i am filling the second combo box. This is taking more time. Is there any method which I can fill the second combo box with the first one? Please Help me... Thanx, Ravi.
-
I have a form which is having two combo boxes. This two combo boxes contains the same list. This list is retrieved from the database. First, I am filling the first combo box and then i am filling the second combo box. This is taking more time. Is there any method which I can fill the second combo box with the first one? Please Help me... Thanx, Ravi.
The easiest way to do it would be to copy the items, one at a time, from one combobox to the other.
Dim index As Integer ComboBox2.Items.Clear() For Index = 0 To ComboBox1.Items.Count() - 1 ComboBox2.Items.Add( ComboBox1.Items(Index) ) Next
Or you could bind the Items collection of one Combobox to the other.
ComboBox2.DataBindings.Add(New \_ Binding("Items", ComboBox1.Items, "")
RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
The easiest way to do it would be to copy the items, one at a time, from one combobox to the other.
Dim index As Integer ComboBox2.Items.Clear() For Index = 0 To ComboBox1.Items.Count() - 1 ComboBox2.Items.Add( ComboBox1.Items(Index) ) Next
Or you could bind the Items collection of one Combobox to the other.
ComboBox2.DataBindings.Add(New \_ Binding("Items", ComboBox1.Items, "")
RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Try using the CopyTo method of the first combobox to copy its contents to an array then use the AddRange method of the second combobox to copy the array.
-
The easiest way to do it would be to copy the items, one at a time, from one combobox to the other.
Dim index As Integer ComboBox2.Items.Clear() For Index = 0 To ComboBox1.Items.Count() - 1 ComboBox2.Items.Add( ComboBox1.Items(Index) ) Next
Or you could bind the Items collection of one Combobox to the other.
ComboBox2.DataBindings.Add(New \_ Binding("Items", ComboBox1.Items, "")
RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
You didn't say you were using VB6 before. Is there some reason you can't fill both ComboBoxes at the same time? That way, you're only enumerating the data once. Otherwise, you have to enumerate the data again, either from the datasource or from the first ComboBox, to fill the second ComboBox. You could still try databinding, but it's a bit more complex than the .NET version. Try this[^] for an example in VB6. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome