CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2003
    Posts
    938

    Population a listBox

    hello.
    how do i populate a listbox with data?
    thnx

  2. #2
    Join Date
    Oct 2001
    Location
    Melbourne, Australia
    Posts
    576

    Re: Population a listBox

    listBox1.Items.Add("abc")

  3. #3
    Join Date
    Aug 2003
    Posts
    938

    Re: Population a listBox

    hey, how do i also check what item is selected. I got a function that handles the double click, how do i get whihc item in the lsit box is selected?(number of it...index of it if u may)

  4. #4
    Join Date
    Dec 2003
    Location
    St. Cugat - Catalunya
    Posts
    441

    Re: Population a listBox

    Quell,
    use ListView1.SelectedItems collection:

    ListView1.SelectedItems.Count
    ListView1.SelectedItems(i)

    Hope it helps
    Did it help? rate it.

    The best conversation I had was over forty million years ago ... and that was with a coffee machine.

  5. #5
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: Population a listBox

    Quote Originally Posted by DeepButi
    Quell,
    use ListView1.SelectedItems collection:
    ...

    Hope it helps
    Did you realize what the OP is asking in the first place?
    He is asking about ListBox and not ListView. List box holds (commonly) only one column, and list view (generally) holds more than 1 columns. List view is like Detailed view in Windows explorer, whereas list-box is like fonts list in Font dialogs (which are actually Combo-boxes).

    If you actually meant ListBox, instead of ListView, your code is perfect!
    Last edited by Ajay Vijay; March 16th, 2005 at 11:23 AM.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  6. #6
    Join Date
    Dec 2003
    Location
    St. Cugat - Catalunya
    Posts
    441

    Re: Population a listBox

    Oooops! true ... one hundred milion times sorry. I meant ListBox1 .

    (Although nothing prevents you from using ListView1 as the ListBox name )
    Did it help? rate it.

    The best conversation I had was over forty million years ago ... and that was with a coffee machine.

  7. #7
    Join Date
    Mar 2005
    Location
    India
    Posts
    45

    Re: Population a listBox

    If u want do this i think the following code must be useful

    Code:
    Dim i, a As Integer
    For i = 0 To ListBox1.SelectedItems.Count() - 1
    'Do Ur processing here what do you want
    a=ListBox1.SelectedItems(i)
    'a hold the current i element's index in main listbox1 Array
    Next
    Hope it is useful 4 u

    Best of Luck

    Regards
    Gurmeet

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

Featured