|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Adding items to a ComboBoxPrivate 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. Show quote "Alex C. Barberi" <AlexCBarb***@discussions.microsoft.com> schrieb im Newsbeitrag news:47043162-4F2C-43D8-BDEE-34FC2FE48CD8@microsoft.com... > 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? > > -- > Alex C. Barberi > Chief Executive Officer > VisionForce > http://www.visionforceweb.com > Thanks! I don't know why I didn't think of that.
Show quote "cody" wrote: > 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. > > "Alex C. Barberi" <AlexCBarb***@discussions.microsoft.com> schrieb im > Newsbeitrag news:47043162-4F2C-43D8-BDEE-34FC2FE48CD8@microsoft.com... > > 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? > > > > -- > > Alex C. Barberi > > Chief Executive Officer > > VisionForce > > http://www.visionforceweb.com > > > > > |
|||||||||||||||||||||||