Hi, I am writing a program that has a listbox which is bound to a dataset. When I click a button (e.g. delete) the item is deleted from the database ok using an SQL query but is still shown in the listbox. How do I get the listbox to refresh/update its display? Any help is greatly appreciated.

Hi,

Personally, I wouldn't refresh the entire listbox. I'd just (programatically) select the relevant listbox item and remove it in the button click event.

Chris.

Hi
I have tried to do both of these methods but neither of them seem to work. I tried unbinding the datasource then rebinding it again and I also tried:

Dim a As Object
a = List.Text
teachersList.Items.Remove(a)

Is there something I'm missing?

Re-bind steps:

1. Fetch data from the database - you can use Fill method of dataAdapter.
2. Assign datasource to the listbox.

To remove a listbox item:

Me.teachersList.Items.Remove(Me.teachersList.SelectedItem)

Thanks to both of you for your help. I can't get the remove selected item way to work so I'm trying this way:

Re-bind steps:

1. Fetch data from the database - you can use Fill method of dataAdapter.
2. Assign datasource to the listbox.

I'm getting the data from the database:

UsersTableAdapter.Fill(DataSet2.Users)

How do I then assign the datasource to my listbox?

This question has already been answered. Start a new discussion instead.