|
-
Mar 27th, 2007, 03:50 AM
#1
[RESOLVED] [2005] Listbox
Dear All,
Is there any way avl to get the items of the listbox in a array without looping .
Dana
Please mark you thread resolved using the Thread Tools as shown
-
Mar 27th, 2007, 04:02 AM
#2
Re: [2005] Listbox
This is a recording. If you want to do something to or with a class then the first thing you should do is read the documentation for the class and its member listing. More often than not you will find exactly what you need very quickly.
Go to the MSDN help topic for the ListBox class and click the Members link. You're interested in the Items property so click that link. The property is type ObjectCollection so click that link to read the documentation for that class. Click its Members link. Shazzam! 20 seconds worth of searching and you find the ListBox.ObjectCollection.CopyTo method, which the documentation describes like so:
Copies the entire collection into an existing array of objects at a specified location within the array.
See how easy that was?
-
Mar 27th, 2007, 04:32 AM
#3
Re: [2005] Listbox
Thks JMC.
What a simple Thing.I need one info also.How can I create context menu
using the contextmenustrip
Dana
Please mark you thread resolved using the Thread Tools as shown
-
Mar 27th, 2007, 04:47 AM
#4
Re: [2005] Listbox
I am trying like this ?
vb Code:
Dim myitem As ToolStripItem = Me.cmnuAllAll.Items.Item(1) 'get the second item
Dim lstdeptcol As ListBox.ObjectCollection = lstDept.Items 'get listbox collection
Dim sString(lstdeptcol.Count) As String
lstdeptcol.CopyTo(sString, 0) 'get the listbox collection
Dim mymainitem As ToolStripMenuItem = DirectCast(myitem,
ToolStripMenuItem)
mymainitem.DropDown.Items. ?
'Now I am trying to create a toolstrip menu item using sString in myitem
Last edited by danasegarane; Mar 27th, 2007 at 04:54 AM.
Please mark you thread resolved using the Thread Tools as shown
-
Mar 27th, 2007, 06:23 AM
#5
Re: [2005] Listbox
vb Code:
Dim upperBound As Integer = myListBox.Items.Count - 1
Dim menuItems(upperBound) As ToolStripMenuItem
For index As Integer = 0 To upperBound Step 1
menuItems(index) = New ToolStripMenuItem(myListBox.GetItemText(myListBox.Items(index)), _
Nothing, _
AddressOf ToolStripMenuItem_Click)
Next index
myToolStripMenuItem.DropDownItems.AddRange(menuItems)
where ToolStripMenuItem_Click is a method that you have declared to handle the Click event of the menu items you create at run time.
-
Mar 27th, 2007, 06:28 AM
#6
Re: [2005] Listbox
Dear JMC,
Thanks for the reply.It is working excellently.Is there any method without looping(If Possible only).
Dan
Please mark you thread resolved using the Thread Tools as shown
-
Mar 27th, 2007, 05:38 PM
#7
Re: [2005] Listbox
You can use the Array.ForEach method. Please don't ask for an example until you've read the documentation, and make sure that you follow the link provided and read about the Action delegate too.
-
Mar 27th, 2007, 11:06 PM
#8
Please mark you thread resolved using the Thread Tools as shown
-
Mar 27th, 2007, 11:26 PM
#9
Re: [2005] Listbox
I'm not saying that I wouldn't provide an example, but I would hope that you'd do what you could to get as much information and understanding as you can yourself first. If you could do it yourself without help wouldn't that be a good thing? If you can't then so be it, but it's worth trying first.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|