Adding items to a ComboBox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Currently, I'm doing this:

Private Sub Populate()
cboCategory.Items.Clear()
cboSubcategory.Items.Clear()
cboFileCategory.Items.Clear()
cboSubcategory.Items.Add("Root")
cboFileCategory.Items.Add("Root")
For Each cCat In Categories
cboCategory.Items.Add(cCat.Name)
cboSubcategory.Items.Add(cCat.Name)
cboFileCategory.Items.Add(cCat.Name)
Next
End Sub

Now it seems like it would be more efficient to add the items to
cboCategory, then use something like the AddRange method like this:
Private Sub Populate()
cboCategory.Items.Clear()
cboSubcategory.Items.Clear()
cboFileCategory.Items.Clear()
cboSubcategory.Items.Add("Root")
For Each cCat In Categories
cboCategory.Items.Add(cCat.Name)
Next

cboSubcategory.Items.AddRange(cboCategory.Items)
cboFileCategory.Items.AddRange(cboSubcategory.Items)
End Sub

Now of course, the above doesn't work; but is there a way to accomplish this?
 
Make a loop adding the names to an Array an after that you can use AddRange.
Adding items to an array is somewhat faster than adding them to a combobox.

alternatively you can use databindung which should even be faster.
 
Back
Top