PC Review


Reply
Thread Tools Rate Thread

AddRange method for CheckedListBox

 
 
=?Utf-8?B?RGF2aWQgTW9ycmlz?=
Guest
Posts: n/a
 
      13th Apr 2004
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
 
Reply With Quote
 
 
 
 
Steve Hoag [MS]
Guest
Posts: n/a
 
      13th Apr 2004
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



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      13th Apr 2004
* =?Utf-8?B?RGF2aWQgTW9ycmlz?= <(E-Mail Removed)> scripsit:
> 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.


\\\
Me.CheckedListBox1.Items.AddRange(New Object() {"Hello", "World", "Foo", 1, 2, "Goo", 1.2})
///

Replace the 'Object' with the type of items if you add only items of the
same type.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CheckedListBox have almost two identical method for checking an item Tony Johansson Microsoft C# .NET 1 4th Sep 2010 12:37 PM
C# version of VB.NET "AddRange" method w/generic collection dgraper Microsoft C# .NET 2 7th Apr 2008 03:48 PM
ArrayLists and AddRange t f Microsoft C# .NET 8 14th Mar 2007 08:54 PM
ArrayList.AddRange() =?Utf-8?B?QW50?= Microsoft C# .NET 4 3rd Nov 2006 02:33 PM
AddRange dalorzo Microsoft Dot NET Framework 0 24th Nov 2003 02:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:03 AM.