Answered by:
How to enable only one selected ListBox at a time

Question
-
I have two ListBoxes: "OnlineProjects" and "Projects" I want the user to be able to select an item from one of them, but not both. when the user clicks on a one ListBox and the an item from the other listbox is selected, the currently selected item will be unselected, and the item the users clicks on will be selected instead.
Is it possible?
Thank you in advance!
- Edited by avivgood Monday, November 18, 2019 4:30 PM
Answers
-
Hi avivgood,
You can clear a ListBox’s selection by setting “SelectedIndex = -1”.
Here is my code you can refer to.
private void OnlineProjects_SelectedIndexChanged(object sender, EventArgs e) { if (OnlineProjects.SelectedIndex > -1) { Projects.SelectedIndex = -1; } } private void Projects_SelectedIndexChanged(object sender, EventArgs e) { if (Projects.SelectedIndex > -1) { OnlineProjects.SelectedIndex = -1; }
}
Best Regards,
Daniel Zhang
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
- Edited by Daniel_Zhang-MSFTMicrosoft contingent staff Tuesday, November 19, 2019 2:52 AM
- Marked as answer by avivgood Tuesday, November 19, 2019 5:40 AM
All replies
-
-
Hi avivgood,
You can clear a ListBox’s selection by setting “SelectedIndex = -1”.
Here is my code you can refer to.
private void OnlineProjects_SelectedIndexChanged(object sender, EventArgs e) { if (OnlineProjects.SelectedIndex > -1) { Projects.SelectedIndex = -1; } } private void Projects_SelectedIndexChanged(object sender, EventArgs e) { if (Projects.SelectedIndex > -1) { OnlineProjects.SelectedIndex = -1; }
}
Best Regards,
Daniel Zhang
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
- Edited by Daniel_Zhang-MSFTMicrosoft contingent staff Tuesday, November 19, 2019 2:52 AM
- Marked as answer by avivgood Tuesday, November 19, 2019 5:40 AM