views:

24

answers:

1

At least one item always remain selected in ListBox. I want that when user clicks empty area of ListBox, selection should be cleared. How to do this?

I am trying to replicate Opera Notes as a part of my application. First i was using a binded DataGridView now i am using a binded ListBox on left pane

+1  A: 

Handle the ListBox.MouseDown event.

Call ListBox.IndexFromPoint, passing the Location property from the MouseDown event's MouseEventArgs parameter.

This should return the index of the item that was clicked, or ListBox.NoMatches if the click was on an empty area.

If the return value is ListBox.NoMatches, set the ListBox.SelectedIndex property to -1 to clear the selection.

Avalanchis
Thanks! I did it with listbox, can i do the same with datagrid view?
LifeH2O