So, if the clicked item is not selected, it should select it. If the item is selected it should deselect it.
THis is much like hte SelectionMode.MultiSimple except that only one item should be selected.
What is the best way to accomplish this?
4 Answers, 1 is accepted
As long as I understand your requirement, it is like listbox items with the radio button behavior. If this is the case, I would suggest the following solution I came around:
|int oldIndex = -1;|
|private void radListBox1_SelectedIndexChanged(object sender, EventArgs e)|
|if (radListBox1.SelectedIndex != -1 && radListBox1.SelectedIndex == oldIndex)|
|radListBox1.SelectedIndex = -1;|
|oldIndex = -1;|
|oldIndex = radListBox1.SelectedIndex;|
I hope this helps. If you encounter any additional problems with this scenario, please do not hesitate to write us again.
All the best,
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Thank you for sharing your thoughts.
The answer of my colleague Georgi concerned quite an old version of RadListBox. You are correct about the SelectedIndexChanged - if an item is selected and the user tries to 'deselect' it, the SelectedIndexChanged event will not be fired neither for the obsolete RadListBox control, nor for its successor RadListControl. Instead, as you have mentioned, we should subscribe to the Mouse events and implement the desired logic there. In the context of RadListControl for WinForms, the code looks like this:
If you have additional feedback to share, feel free to write back. All the best,
the Telerik team
;seems to work on screen, but doesn't clear the .SelectedIndex property of the list control. Instead I used
radListControl1.SelectedIndex = -1to deselect and it worked just fine.