Listbox

pruebens

Regular
Joined
Nov 21, 2002
Messages
71
Hello. Not sure where to post this.

I've got a form that has a listbox that pulls it's data from a database and also has 10 empty textboxes on there as well.

How do I make it so that when a user double clicks on one of the entries in the listbox it automatically moves what they double click over to the next empty textbox?

Thanks.
 
here's a small sample...
Visual Basic:
    Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        If Not AddToTextbox(ListBox1.SelectedItem) Then
            MessageBox.Show("sorry all text boxes are full")
        End If
    End Sub

    Private Function AddToTextbox(ByVal txt As String) As Boolean
        Dim ctr As Control
        For Each ctr In Me.Controls
            If TypeOf ctr Is TextBox Then
                If ctr.Text.Length = 0 Then
                    ctr.Text = txt
                    Return True
                    Exit Function
                End If
            End If
        Next
        Return False
    End Function
 
no problem...
also, if you want to remove the clicked item once it's in the textbox...

Visual Basic:
        If Not AddToTextbox(ListBox1.SelectedItem) Then
            MessageBox.Show("sorry all text boxes are full")
        Else
            ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
        End If
 
Back
Top