unselect item in listbox

G

Guest

i have a listbox w/ single select mode. Can a user unselect an item by
clicking on it? How is it implemented?

Thanks
 
A

Adam Benson

You could try implementing a selected index changed handler.

I think this will fire if you select an item that's already selected and in
your handler, if the item just selected is the same as the last selected
item, set SelectedIndex to -1.

Something like this :

private int lastindex = -1;

private void mylist_SelectedIndexChanged(object sender, EventArgs e)
{
if (mylist.SelectedIndex == lastindex)
{
lastindex = -1;
mylist.SelectedIndex = -1;
return;
}

lastindex = mylist.SelectedIndex;

}

I must stress I haven't tried this; it's just a sketch. Anyway, give it a
spin; see if it works.

HTH,

Adam.
=====
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top