WPF Listbox with checkboxes

11 posts, 0 answers
  1. James
    James avatar
    4 posts
    Member since:
    Feb 2014

    Posted 21 Feb 2014 Link to this post

    I would like to create a listbox that contains checkboxes similar to this, but for WPF:

    http://demos.telerik.com/aspnet-ajax/listbox/examples/functionality/checkboxes/defaultcs.aspx

    Notice in this demo that you can still 'select' a single row - independent of the checkboxes.  I need to preserve that functionality.  I just want to add checkboxes next to each item that can be checked (one or more).  I also need to know how to get the checked items.

    Thank you,
    James DiEdwardo
  2. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 24 Feb 2014 Link to this post

    Hi James,

    The ListBox for WPF doesn't provide built-in CheckBoxes functionality, but you could easily implement it by yourself. You will need to apply ItemTemplate which contains CheckBox and TextBlock for example which TextBlock will be bound to a property in the custom object from the ListBox ItemsSource collection. As for the CheckBoxes they can be bound to the IsSelected property of each ListBoxItem, so whenever you check a CheckBox the item gets selected. Finally in order to get the checked items you could just use the SelectedItems collection of the ListBox which will contain only the selected ones. For your convenience I have prepared and attached a sample project which demonstrates the exact approach.

    Hope this helps. 

    Regards,
    Kalin
    Telerik
  3. UI for WPF is Visual Studio 2017 Ready
  4. James
    James avatar
    4 posts
    Member since:
    Feb 2014

    Posted 24 Feb 2014 in reply to Kalin Link to this post

    Thanks for the reply, however what I need is a ListBox that allows users to SELECT a single item at time.  But then I also want to add a checkbox next to each item that allows multiple items to be CHECKED (and a way to detect which ones are checked).   Just like in this example (but I need a WPF version):  http://demos.telerik.com/aspnet-ajax/listbox/examples/functionality/checkboxes/defaultcs.aspx

    I also attached a screenshot of the example showing how it allows you to select a single item, but CHECK multiple items.

  5. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 25 Feb 2014 Link to this post

    Hello James,

    I modified the sample project from the previous post in order to demonstrate the exact scenario from the mentioned example but for WPF. Only single item can be selected and when the button is clicked it gets all of the items which have checked CheckBoxes.

    Hope this will work for you.

    Regards,
    Kalin
    Telerik
  6. James
    James avatar
    4 posts
    Member since:
    Feb 2014

    Posted 25 Feb 2014 in reply to Kalin Link to this post

    Thank you!  It appears that this is a VS 2013 project... would it be convenient for you to output as 2010?
  7. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 26 Feb 2014 Link to this post

    Hi James,

    I modified the project in order to be runnable in VS 2010. Please try it the attached project and let me know if you still have any issues.

    Regards,
    Kalin
    Telerik
  8. James
    James avatar
    4 posts
    Member since:
    Feb 2014

    Posted 26 Feb 2014 in reply to Kalin Link to this post

    I think you may have forgotten to attach?
  9. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 26 Feb 2014 Link to this post

    Hello James,

    I'm sorry about that - please check my previous post again for the attached sample project.

    Regards,
    Kalin
    Telerik
  10. Nir
    Nir avatar
    4 posts
    Member since:
    Apr 2014

    Posted 11 May 2014 Link to this post

    Thank you very much, that was very helpful :)
  11. Stephen
    Stephen avatar
    17 posts
    Member since:
    Aug 2013

    Posted 14 May 2015 in reply to Kalin Link to this post

    kalin, this was great! the demonstration project was simple and to the point, and easy to follow. It solved my users' requests.

    thanks!

  12. Stephen
    Stephen avatar
    17 posts
    Member since:
    Aug 2013

    Posted 14 May 2015 in reply to Kalin Link to this post

    kalin, thanks. your attached project was simple and to the point, and easy to follow. it solved the issue our users had requested in quite an elegant fashion

    thanks!

    stephen

Back to Top
UI for WPF is Visual Studio 2017 Ready