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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top