Results 1 to 3 of 3

Thread: [RESOLVED] Hashtable and listbox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    124

    Resolved [RESOLVED] Hashtable and listbox

    I would like to know what code would take all Keys from a Hashtable and add them to a listbox. Thanks
    Last edited by martw; Nov 19th, 2005 at 03:22 AM. Reason: solved
    I never know what to put in this section...



    So sue me... ... ... I'm just kidding...


    www.fat-pie.com Flash Movies... You gotta see 'em to believe 'em!

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

    Re: Hashtable and listbox

    VB Code:
    1. Dim myArray(myHasTable.Count - 1) As String
    2.  
    3. myHashTable.Keys.CopyTo(myArray, 0)
    4. myListBox.Items.AddRange(myArray)
    You could use the following instead, but it is preferable to use AddRange to add multiple items than multiple calls to Add:
    VB Code:
    1. For Each key As String In myHashTable.Keys
    2.     myListBox.Items.Add(key)
    3. Next key
    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
    Lively Member
    Join Date
    Mar 2005
    Posts
    124

    Re: Hashtable and listbox

    jmcilhinney, You are a genious Thanks.
    I never know what to put in this section...



    So sue me... ... ... I'm just kidding...


    www.fat-pie.com Flash Movies... You gotta see 'em to believe 'em!

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