Results 1 to 6 of 6

Thread: ListBox Question

  1. #1

    Thread Starter
    Addicted Member Smie's Avatar
    Join Date
    Jun 1999
    Location
    Columbus, OH
    Posts
    249

    Post

    How would I make a textbox = list1's 3rd selection? For example, when a button is pressed, the 3rd value, or 3rd item from the top(not sure what to call it), pops into the textbox, i have a good idea on what to do, but nothing will work, please help, thanx

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    Try this:
    Add a ListBox, CommandButton and TextBox to your form, then paste this code:
    Code:
    Option Explicit
    Public Index As Integer
    
    Private Sub Command1_Click()
        Text1.Text = List1.List(Index)
    End Sub
    
    Private Sub Form_Load()
        Dim I As Integer
        With List1
            For I = 1 To 10
                .AddItem I
            Next I
        End With
    End Sub
    
    Private Sub List1_Click()
        Index = List1.ListIndex
    End Sub
    I hope this will help

    ------------------
    Visual Basic Programmer
    ------------------
    PolComSoft
    You will hear a lot about it.


  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Do you mean how do you access the 3rd Item Down from the Visible Top of the Listbox?
    Code:
    Private Sub Command1_Click()
        If List1.TopIndex + 2 < List1.ListCount Then
            Text1 = List1.List(List1.TopIndex + 2)
        Else
            Text1 = List1.List(List1.ListCount - 1)
        End If
    End Sub
    Otherwise, if you mean how do you access the 3rd Item Period..
    Text1 = List1.List(2)


    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  4. #4

    Thread Starter
    Addicted Member Smie's Avatar
    Join Date
    Jun 1999
    Location
    Columbus, OH
    Posts
    249

    Post

    Im a little confused, what you gave me, even though i appreciate your help, was not what i was looking for, maybe if im more specific:

    Say i have 10 items in the listbox. I also have 10 textboxes. What would i do, so at a push of a button, the each listbox item, is now in a seprate textbox.

  5. #5

    Thread Starter
    Addicted Member Smie's Avatar
    Join Date
    Jun 1999
    Location
    Columbus, OH
    Posts
    249

    Post

    Thanks aaron, thats what ive been looking for

  6. #6
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    If that's your problem then use this:
    Create an array of 10 textboxes, add 10 items to a listbox and paste this code:
    Code:
    Private Sub Command1_Click()
        Dim I As Integer
        For I = 0 to List1.ListCount - 1
            Text1(I).Text = List1.List(I)
        Next I
    End Sub
    Hope This will help

    ------------------
    Visual Basic Programmer
    ------------------
    PolComSoft
    You will hear a lot about it.


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