CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: ListBox values

  1. #1
    Join Date
    Oct 2001
    Location
    England
    Posts
    2

    ListBox values

    I am using the me.lstbox.selected(x) = true to scroll up and down a listbox. This seems to alter the selected row, but does not actually seem to select the row (like it would if you clicked on it).

    The problems I am having is that I need to get the value of the row that the selection has moved to, has anybody got any ideas?

    Cheers

    Stu


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: ListBox values

    Try
    if List1.Selected(index) = True then
    msgbox List1.Text
    end if


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Sep 2001
    Location
    Montreal Canada
    Posts
    1,080

    Re: ListBox values


    msgbox Listbox.ItemData(listbox.ItemsSelected.Item(0))




    0 is for the first element selected if you enabled multiselection then you'll have to loop. Sample loop is


    for counter = 0 to (listbox.ItemsSelected.Count -1 )
    msgbox listbox.itemdata(listbox.itemsselected.item(counter))
    next




    Nicolas Bohemier

  4. #4
    Join Date
    Sep 2001
    Location
    Montreal Canada
    Posts
    1,080

    Re: ListBox values

    Disregard my previous message, it works on Access.. On VB 6 use this


    msgbox List1.ItemData (List1.Selected(0))

    for Counter = 0 to list1.Selcount -1
    msgbox list1.ItemData(List1.Selected(counter))
    next



    Nic

    Nicolas Bohemier

  5. #5
    Join Date
    May 2001
    Location
    Canada
    Posts
    182

    Re: ListBox values

    Instead of using :

    lstbox.selected(x)= true

    Try this:

    lstbox.ListIndex=x



    Regards,

    Michi

  6. #6
    Join Date
    Sep 2001
    Location
    Montreal Canada
    Posts
    1,080

    Re: ListBox values

    Disregard both last messages I thought that it was working nevermind.

    Nicolas Bohemier

  7. #7
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: ListBox values

    I apparently do not understand the problem. I tried this sample progra below without any problems. When I select a list item in the listbox, It is viewable and highlighted. When I display it it comes out OK
    Place a Listbox, 2 command buttons and a textbox on a form. Paste this code.
    Enter a number in textbox and click Button1
    Item is displayed highlighted in listbox
    click button2. Item is displayed correctly

    private Sub Command1_Click()
    List1.Selected(Text1.Text) = true
    End Sub

    private Sub Command2_Click()
    MsgBox List1.List(List1.ListIndex)
    End Sub

    private Sub Form_Load()
    Dim X
    for X = 0 to 100
    List1.AddItem X
    next X
    End Sub




    John G

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