473,804 Members | 3,138 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AddRange method for CheckedListBox

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
Nov 20 '05 #1
2 6990
Hi David,

You need to pass either an ObjectCollectio n object or an array to the
AddRange method; these must be defined beforehand. For example:

Dim myItems As New ListBox.ObjectC ollection(Check edListBox1)
myItems.Add("fo o")
myItems.Add("ba r")
myItems.Add("fo obar")

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 ObjectCollectio n 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" <an*******@disc ussions.microso ft.com> wrote in message
news:A2******** *************** ***********@mic rosoft.com...
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

Nov 20 '05 #2
* =?Utf-8?B?RGF2aWQgTW9 ycmlz?= <an*******@disc ussions.microso ft.com> 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.CheckedListB ox1.Items.AddRa nge(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/>
Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4572
by: Matt C. | last post by:
Does the CheckedListBox support DisplayMember/ValueMember? I have been trying to use these properties with the CheckedListBox and they are not working. I see from Google that databinding is not supported on this control. Ok, fine. I tried to work around this by using DictionaryEntries, which still didn't work (see code below). Now I see in VS Help that DM/VM are not even listed as properties of the CheckedListBox (they are in VS...
1
5580
by: Sylvain | last post by:
Hi, I'm encountering a very simple issue with ArrayList constructor and AddRange() method overriding. I'm defining a class that extends ArrayList and contains one overriden method: AddRange(ICollection). public class Test:ArrayList {
4
3798
by: Matthew | last post by:
Hi, I am using a checkedlistbox on a windows form and binding it to a collection of classes. clbAliases is the checkedlistbox control selectedplace is a class with property placealiases.This property is a collection of placealias classes. Hopefully the rest is self-explanatory..
8
1806
by: Derek Martin | last post by:
Here is some code that I need help with please: Dim result As New ArrayList Try For i = 0 To objecttest1.PersonList.person_returnnumber - 1 result = objecttest1.PersonList.time_returnpunches(objecttest1.PersonList.person_getb yid(i).userid, "03/08/2004", "03/09/2004", True, False) 'The above line returns an object with several proerties, namely, a punch id that I want to be able to get out of the checkedlistbox collection:
0
315
by: David Morris | last post by:
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 "{...
2
2311
by: Manuel Canas | last post by:
Hi there, I'm having this dilema with a checkedlistbox. I have an array of items in there, what I want to accomplish is the following; The user could check all the items in the checkedlistbox, but always have at list one item always checked. so if the user has the last item checked and he/she wants to uncheck it, the item should reset it self to a checked state
0
1719
by: Terry Olsen | last post by:
Dim dirs() as string = Directory.GetDirectories(MyPath) CheckedListBox.DataSource = dirs CheckedListBox.Update For I as Integer = 0 To CheckedListBox.Items.Count - 1 CheckedListBox.SelectedIndex = I DoMySub(CheckedListBox.SelectedItem) Next The first line in the For loop (CheckedListBox.SelectedIndex = I) sometimes
5
6871
by: mabond | last post by:
Hi Can't believe I've not been able to find the answer to this in the on-line help. I have a CheckedListBox which, via a timer control, is populated with the names of files in a network folder. The "check mark" for each item in the control is determined by the boolean value of a custom property field of the file. That value is found using microsoft's dsofile.dll class.
6
6937
by: Steve Teeples | last post by:
Can someone show me an example of how to place a "CheckedListBox" property within a PropertyGrid? -- ----------- Thanks, Steve
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9152
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.