473,804 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

load arrayList into ListBox.ObjectC ollection

This is wrong but it seems I might be on track somewhat close:
I want to display my ArrayList of Random numbers in the list box.
Below you see this as aLRandoms.

There seems to be a provision to load a range :
listBox1.Items. AddRange(lboxOb jCol);

so I try to load the lboxObjCol as shown:
System.Windows. Forms.ListBox.O bjectCollection lboxObjCol = new
ListBox.ObjectC ollection(listB ox1, (object)aLRando ms);
where the 2nd param is Object [] value ...

thanks
--
Andrew
Feb 15 '06 #1
2 15627
Here's the answer after some digging: ( answer by self )

int intMaxElements = aLRandoms.Count ; // where aLRandoms is an ArrayList
object[] bunchOfStuff = new object[intMaxElements];
System.Windows. Forms.ListBox.O bjectCollection lboxObjCol = new
ListBox.ObjectC ollection(listB ox1, bunchOfStuff);
listBox1.Items. AddRange(lboxOb jCol);

Works perfectly.....
--
Andrew
"andrewcw" wrote:
This is wrong but it seems I might be on track somewhat close:
I want to display my ArrayList of Random numbers in the list box.
Below you see this as aLRandoms.

There seems to be a provision to load a range :
listBox1.Items. AddRange(lboxOb jCol);

so I try to load the lboxObjCol as shown:
System.Windows. Forms.ListBox.O bjectCollection lboxObjCol = new
ListBox.ObjectC ollection(listB ox1, (object)aLRando ms);
where the 2nd param is Object [] value ...

thanks
--
Andrew

Feb 15 '06 #2
// forgot to add : cRandoms.CopyTo (bunchOfStuff);

int intMaxElements = cRandoms.Count;
object[] bunchOfStuff = new object[intMaxElements];
cRandoms.CopyTo (bunchOfStuff);
System.Windows. Forms.ListBox.O bjectCollection lboxObjCol = new
ListBox.ObjectC ollection(listB ox1, bunchOfStuff);
listBox1.Items. AddRange(lboxOb jCol);
--
Andrew
"andrewcw" wrote:
Here's the answer after some digging: ( answer by self )

int intMaxElements = aLRandoms.Count ; // where aLRandoms is an ArrayList
object[] bunchOfStuff = new object[intMaxElements];
System.Windows. Forms.ListBox.O bjectCollection lboxObjCol = new
ListBox.ObjectC ollection(listB ox1, bunchOfStuff);
listBox1.Items. AddRange(lboxOb jCol);

Works perfectly.....
--
Andrew
"andrewcw" wrote:
This is wrong but it seems I might be on track somewhat close:
I want to display my ArrayList of Random numbers in the list box.
Below you see this as aLRandoms.

There seems to be a provision to load a range :
listBox1.Items. AddRange(lboxOb jCol);

so I try to load the lboxObjCol as shown:
System.Windows. Forms.ListBox.O bjectCollection lboxObjCol = new
ListBox.ObjectC ollection(listB ox1, (object)aLRando ms);
where the 2nd param is Object [] value ...

thanks
--
Andrew

Feb 15 '06 #3

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

Similar topics

4
5912
by: Jason | last post by:
Here is an odd issue. I am trying to shed some light on why this is causing a problem. I have an ArrayList. I am binding it to a ListBox control with has its Sort property set to True. If the ArrayList only has one element in it everything works ok. But as soon as I have more than one element, I get the following exception when the control loads up: "Cannot modify the Items collection when the DataSource property is set.". Anybody...
3
2477
by: MikeB | last post by:
The .NET 1.1 documentation declares that there is a GetEnumerator method associated with the ListBox.ObjectCollection class. When I try to implement this as follows: IEnumerator posControls = ListBox.ObjectCollection.GetEnumerator(); The autocompletion mechanism shows only two methods: Equals() and ReferenceEquals()
3
1985
by: RBCC | last post by:
I have a form with a listbox and two textboxes. In the listbox I have the make and models of automobiles. and as the user clicks on the make of the car in the listbox I would like to output the make and model in the textboxes, how is this done with an arraylist John --- Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
5
2438
by: John Veldthuis | last post by:
My code works perfectly 100% when adding items to my ArrayList and updating the listbox. Works perfectly when deleting an item in the ArrayList when it is not the last entry but if it is the last entry and you select another index it goes boom!!!. Funny thing is the SelectedIndex Changed routine fires off perfectly and then crash after the return from this code. Now looking around the news groups it appears to be a bug in the .net...
3
3532
by: andrewcw | last post by:
Who can explain this ?? : I expect 2 but I get 4 items ! private void button1_Click(object sender, EventArgs e) { object bunchOfStuff = { "foo", "fee" }; listBox1.Items.Clear(); System.Windows.Forms.ListBox.ObjectCollection lboxObjCol = new ListBox.ObjectCollection(listBox1, bunchOfStuff); listBox1.Items.AddRange(lboxObjCol);
2
1829
by: AppleBag | last post by:
Hello everybody, I am beginning the .NET learning curve, and I have learned how to load a listbox with a directory list of files using this code: If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then ListBox1.DataSource = System.IO.Directory.GetFiles(FolderBrowserDialog1.SelectedPath)
6
3966
by: Zytan | last post by:
In win32 there was a way to 'turn off' a listbox from updating until you were done adding elements. Is there a way to do this in .NET? Zytan
5
7436
by: markr1000 | last post by:
I must have looked searched in 500+ places that showed up in Google searchs, but not one has an example of what I want to do. I have a Listbox on a User Control because I want to control the visibility and/or presence of the Listbox and associated label, and I want to encapsulate some of associated code. I want to be able to pass the collection of strings that will fill the Listbox to the User Control and have it pass on the collection...
4
2151
by: Anand Ganesh | last post by:
Hello All, I want to go through each item in a Listbox collection. How will I do this? I was looking for ListBoxItem but nothing is available? Any suggestions please? Thanks Anand Ganesh
0
9716
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
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10604
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10359
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
10101
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9177
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
7643
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
5536
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...
1
4314
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

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.