What I have is a listbox with items imported from the database. From the Data Sources (Shift+Alt+D) I've dragged a table in the form of Details, instead of DataGridView.
What I'm trying to figure out, is how to make the information to be displayed in the Details when an item is selected from the listbox.
See the picture for clarification.

Does the information in the Listbox (retreived by SQL Query) is using the same table shown in picture? or there is 2 (table and query)?

The table has all the items in it, and the listbox has a query which populates it with the items.

Dragging data source to the form will create a bindingsource for you (Let assume that the bindingsource name is bs_detail)

Use the Find("FieldName",FieldValue) to find the required row depending on the listbox selection, so basically you should not code more that the below

I used "ID", change it to the field name you have in your table

Private Sub lstListBox1_SelectedIndexChanged( sender As System.Object,  e As System.EventArgs) Handles lstListBox1.SelectedIndexChanged

        Dim RoomNoInListbox = Me.lstListBox1.SelectedItem()(0)

        bs_detail.Position = bs_detail.Find("id",RoomNoInListbox)
End Sub

So how would I use the "Find" exactly (never did that before)?
AND
Since the details has many labels such as Name, Phone #, E-mail, how would I make each of them to be updated with the information when I select an item from the listbox?

bs_detail.Position = bs_detail.**Find**("id",RoomNoInListbox)
The above line of code I post it earlier will do all that for you since you using bindingsource.

The Find() is a method in Bindingsource

Ok, this code:

If TextBoxSearch.Text = "" Then
            TableBindingSource1.RemoveFilter()
        Else
            TableBindingSource1.Filter = "Last_First_Name LIKE '%" + TextBoxSearch.Text + "%'"
        End If

Updates the Details based on the match, but it doesn't remove the non-matching items from the listbox.
What am I doing wrong?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.