Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Selected index change problem
 

Selected index change problem

I have two forms, the first has a ListBox that is binding to a datasource. When an item is selected, the second form populates it's details.
The problem I'm having is that when I delete an item from the ListBox, the second form does not update despite having SelectedIndexChanged handler that explicitly calls update on the second form.

I think the problem arises from the way I handle the delete. I run SQL delete query for the dataset to perform the delete and then I call Fill to update the ListBox. The Fill seems to set the selected index to -1. Obviously I check that before i update (I can't update for -1).
When the delete and the SelectedIndexChanged handler run through I end up with an item being selected, but the second form still shows the details of the deleted item. Further I do not get a second SelectedIndexChanged event.

Any ideas how to fix that? I use the same approach in 4 different pair of forms and it makes look my app buggy.
Thanks !

Ventsislav Velev  Friday, October 03, 2008 5:53 PM
I worked around the problem. I added an if statement after the delete and fill functions that checks the index of the already deleted item and according to that highligths the next appropriate item.
If the item that was deleted was the last item in the list the first item is highlighted. If there are no items left, obviously nothing is highlighted.

Not very elegant but it works.
Ventsislav Velev  Thursday, October 09, 2008 4:28 PM
I worked around the problem. I added an if statement after the delete and fill functions that checks the index of the already deleted item and according to that highligths the next appropriate item.
If the item that was deleted was the last item in the list the first item is highlighted. If there are no items left, obviously nothing is highlighted.

Not very elegant but it works.
Ventsislav Velev  Thursday, October 09, 2008 4:28 PM

You can use google to search for other answers

Custom Search

More Threads

• Help! - DataBinding Object
• merging cells in datagridview
• Auto commit in sql server off
• Assining Null value to data Field - Help !!!
• Dataset, ManagementObjectSearcher and WMI query - indexed property problems
• Update Listview on another form
• SelectionChangeCommitted not working
• How to stop creating new row during sorting.
• Datagridview - Keypress
• Problem with uploading tableAdapter...