[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1314
  • Last Modified:

WPF Limit listbox selected items to a number /Select, unselect items in listbox

   I have a supposedly simple problem but I am not sure how to implement this. I have created a simple example of the issue with the below attached files. The two files are the ProductWindow xaml and cs file and the Product class file. I want to accomplish two things, please take a look at both and provide the code with your suggestion, thanks.

1) Limit the selected Items in the listbox to 3. How do I implement this for the listbox lbProducts? I didnt see a maxselecteditems property?!? or something similar.

2) This is a little more fun :) the second issue is I add the "All" Item to the datatable before binding the listbox. I would like to unselect other items if the All option is selected by the user and similarly unselect All if the user selected any other item. Also All should clear out the other selected items and we should limit the selected items to 3 only if All is not in the selected items? Hopefully that makes sense, please let me know if you need any other info, your help is really appreciated.  Please take the code from my simple example files below.
1 Solution
I have solved both 1) and 2) (The code is attached)

I have added a variable called MaxItems(set to 3) in ProductWindow code and am handling the SelectionChanged event of the combobox.

groovbox303Author Commented:
Thanks for your help cutebug, you rock!

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now