WPF Datagrid - Need to select all checkboxes.
-
Friday, April 17, 2009 2:59 PMHi
I have a bound WPF Toolkit datagrid. I have added a dynamically generated checkbox column. Does anyone know of a way to select / deselect all checkboxes, based on the value of an off-grid checkbox.
Thanks in advance,
Jules
All Replies
-
Friday, April 17, 2009 3:09 PM
Yes, just add a binding to the IsChecked DependencyProperty of the outside checkbox.I.E.<CheckBox Name="OutsideGridCheckBox"/><CheckBox Name="InsideGridCheckBox1" IsChecked="{Binding ElementName=OutsideGridCheckBox, Path=IsChecked}"/><CheckBox Name="InsideGridCheckBox2" IsChecked="{Binding ElementName=OutsideGridCheckBox, Path=IsChecked}"/>etc...- Marked As Answer by Tao Liang Tuesday, April 21, 2009 3:41 AM
-
Friday, April 17, 2009 3:40 PMHi,
Thanks for the quick reply, however the datagridcheckboxcolumn does not contain "Checked".
I've tried selector.IsChecked, but that doesn't work either.
Cheers
Jules -
Friday, April 17, 2009 3:54 PMPlease post some code and we will try to help you figure it out.
-
Friday, April 17, 2009 3:55 PMFirst, I wouldn't directly bind the checkboxes of the grid to the "Select All" checkbox. This would cause them to be out of sync when a subset of the checkboxes are selected. Instead, use code attached to the CheckBox OnChecked/OnUnchecked events to trigger the data grid to be updated. If it's dynamically generated, then it's based upon a propertyon the underlying object. Does the underlying object implement INotifyPropertyChanged to permit just changing that property directly?
-
Friday, April 17, 2009 3:58 PMHi Richard,
Bit of a newbie when it comes to wpf. Could you post some sample code?
Cheers,
Jules -
Friday, April 17, 2009 4:19 PMHi Richard
Don't put yourself to any trouble. Found a good example on the web.
Thanks very much for your help.
Cheers
Jules -
Monday, April 20, 2009 7:45 AMHi,
I have some problems with my DataGridCheckBoxColumn on my DataGrid : when I want to check one of the checkboxes, I have to double click on it because the line of the DataGrid must be selected to be able to check the checkbox. How could I check it with a simple click ? I can show a messagebox when I click on it, which means I'm able to know that I clicked on the checkbox, but I can't find any property which would say to the checkbox : "check you" :/
And jules140, could you please tell me where did you find a good example of your problem ?
Thanks a lot !
Spixy. -
Monday, April 20, 2009 3:48 PM
Hi Spixy,
Your single select problem: http://blogs.msdn.com/vinsibal/archive/2008/08/27/more-datagrid-samples-custom-sorting-drag-and-drop-of-rows-column-selection-and-single-click-editing.aspx
I couldn't find the example, but I solved it by binding a class to the datagrid and changing all the selected values in the Class, which updated the screen. I am unable to cast any more light on this at the moment, as I am away on business.
Hope this helps,
Jules- Marked As Answer by Tao Liang Tuesday, April 21, 2009 3:41 AM
-
Tuesday, April 21, 2009 3:40 AMDataGrid is not a released product. But you could get help from codeplex.
http://wpf.codeplex.com/Thread/List.aspx -
Tuesday, April 21, 2009 7:15 AMHi !
Thanks for your answers ! I think I've found a solution : I've binded the datagridcheckboxcolumn with a property of my object which is a boolean ; when it's false, the checkbox is not checked, and when it's true it's checked. So with the selectionchanged event of my datagrid, I can know that I've clicked on my checkbox, and I pass my boolean to true or false, and it works :)
I hope I was enough clear because my english is not really good to explain this ^^
Spixy.

