Hi, I implemented a column of checkboxes in my grid for selecting the row. I followed the example here: http://community.infragistics.com/forums/p/52125/271646.aspx
I am trying to implement this for all my grids, so I have derived a new class from XamGrid, and I am using that instead of the base Infragistics class.
The problem is that I want to add a "Check all" checkbox to theheader. I was able to do that by creating a DataTemplate in OnApplyTemplate in XamGrid.cs:
CheckboxStateColumn selectedColumn = new CheckboxStateColumn(CheckedItems); selectedColumn.Key = "IsSelected"; selectedColumn.Width = new ColumnWidth(40, false); selectedColumn.HeaderText = " "; selectedColumn.HeaderTemplate = Application.Current.Resources["CheckAllTemplate"] as DataTemplate; this.Columns.Insert(0, selectedColumn);
CheckAllTemplate is defined like this in a resource dictionary:
<DataTemplate x:Key="CheckAllTemplate"> <CheckBox Command="{Binding CheckAllCheckedCommand}" /> </DataTemplate>
The checkbox shows up, the problem is that my CheckAllCheckedCommand is never called. I think this is because the DataContext is missing. How can I get this to work?
Hello jbaumgartner,
I have been looking into your post and I can suggest looking through the following blog that presents a custom approach on how to add a ‘Select All’ Checkbox to a XamGrid CheckboxColumn Header :
http://blogs.infragistics.com/blogs/devin_rader/archive/2011/04/29/adding-a-select-all-checkbox-to-a-xamgrid-checkboxcolumn-header.aspx
If you need any further assistance on this matter, do not hesitate to ask.
Thanks, I've seen that one. The trouble with that is it requires me to update my model, which I do not want to do, and it is not generic for all grids. I don't want to add code for every single instance of the grid.
I have been looking into your post and I have modified Stephen Zharuk’s sample project adding a checkbox in the header of the column ‘Blegh’ and when check/uncheck all checkboxes in this column respectively change their states. I am sending you the modified project(ModifiedSample.zip).
If I have misunderstood you in any way, please do not hesitate to tell me.
Thanks, Yanko. This solution still requires that I add this DataTemplate to every grid I use, and I would need the Checked / Unchecked event handlers in the codebehind for every control that uses the grid.
I want a separate class, which is derived from XamGrid. Let's call it MyXamGrid. MyXamGrid has a dependency property called "ShowCheckboxes". If this is true, it will insert a CheckboxStateColumn as the first column in the grid.
The styling for MyXamGrid is handled in a resource dictionary, which is loaded in my Application_Startup.
That part works.
But if I add this to my resource dictionary:
<DataTemplate x:Key="CheckAllTemplate"> <<CheckBox Checked="CheckAllChecked" />
</DataTemplate>
I get a XamlParseException: Failed to assign property 'System.Windows.Controls.Primitives.ToggleButton.Checked'. And that makes sense to me.
I tried this with Prism commands, but the DataContext of the checkbox was always the Key of the column, and so I could never fire my command. The DataContextProxy trick didn't even work.
Am I just barking up the wrong tree? Is this simply not possible the way I want to implement?
I am just checking if you require any further assistance on the matter.
For some reason, I wasn't notified about your previous reply. Thanks for that. I'll take a look and see if it works.
Hello,