Results 1 to 9 of 9

Thread: [RESOLVED] [2005] Listbox

  1. #1

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Resolved [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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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

  4. #4

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [2005] Listbox

    I am trying like this ?
    vb Code:
    1. Dim myitem As ToolStripItem = Me.cmnuAllAll.Items.Item(1) 'get the second item
    2.         Dim lstdeptcol As ListBox.ObjectCollection = lstDept.Items  'get listbox collection
    3.         Dim sString(lstdeptcol.Count) As String
    4.         lstdeptcol.CopyTo(sString, 0)       'get the listbox collection
    5.         Dim mymainitem As ToolStripMenuItem = DirectCast(myitem,    
    6.          ToolStripMenuItem)
    7.         mymainitem.DropDown.Items. ?
    8.         '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

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Listbox

    vb Code:
    1. Dim upperBound As Integer = myListBox.Items.Count - 1
    2. Dim menuItems(upperBound) As ToolStripMenuItem
    3.  
    4. For index As Integer = 0 To upperBound Step 1
    5.     menuItems(index) = New ToolStripMenuItem(myListBox.GetItemText(myListBox.Items(index)), _
    6.                                              Nothing, _
    7.                                              AddressOf ToolStripMenuItem_Click)
    8. Next index
    9.  
    10. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [2005] Listbox

    :d :d
    Please mark you thread resolved using the Thread Tools as shown

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width