Hi David,
You need to pass either an ObjectCollection object or an array to the
AddRange method; these must be defined beforehand. For example:
Dim myItems As New ListBox.ObjectCollection(CheckedListBox1)
myItems.Add("foo")
myItems.Add("bar")
myItems.Add("foobar")
CheckedListBox1.Items.AddRange(myItems)
If you are only loading the ListBox once, this doesn't save you any work
over using the Add method, but if you have a common set of ListBox items
that are used in multiple places, using AddRange with an ObjectCollection or
array means you only have to list the items once.
Hope this helps,
Steve Hoag
Visual Basic .NET team
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"David Morris" <(E-Mail Removed)> wrote in message
news:A2052B7B-0E33-419C-A595-(E-Mail Removed)...
> Hi,
>
> I want to add multiple items (about 20) to a checked list box control at
> run time, but do not know how to use the AddRange method of the Items
> collection. Currently, I am using the Add method, which works fine, but
> since I'm dealing with 20 items, this means I have 20 lines of code
> because the Add method is used once for every item.
>
> Could somebody please clarify the syntax of the AddRange method? I know
> you're supposed to use braces "{ }", but I'm just not sure where they go,
> and IntelliSense has got me all confused.
>
> Thanks and Best Regards,
> David Morris
|