Sorting checkbox column in grid
-
Hello, I am using toolkit's datagrid and I have checkbox in one of my columns which I define as below
<toolkit:DataGrid x:Name="m_PositionsGrid"
CanUserSortColumns="True"
MinHeight="200"
MinWidth="100"
><toolkit:DataGrid.Columns> <PrimitivesUI:DataGridValueColumn Binding="{Binding Path=Time, Mode=OneWay}" IsReadOnly="True" Width="170"/> <toolkit:DataGridTemplateColumn > <toolkit:DataGridTemplateColumn.CellTemplate> <DataTemplate> <CheckBox Click="OnUsedClicked" IsChecked="{Binding Path=Used}" /> </DataTemplate> </toolkit:DataGridTemplateColumn.CellTemplate> </toolkit:DataGridTemplateColumn> </toolkit:DataGrid.Columns> </toolkit:DataGrid>
When I do so , And my datagrid gets populated , I can sort on Time column, but say few of my checkboxes are true and some false, then I would like to sort that column as well, so that all true checkbox gets grouped. I do understand that since we have multiple true or multiple false values so sorting cannot happen , but say I would like it to be: first sort on checkbox column and then sort on time column, so by this way all true checkboxes shall be together and they shall be sorted on secondary field time. But I have no idea whether this can be implemented or not, if yes can somebody please point to the code. Thanks BV
-
Hello, I am using toolkit's datagrid and I have checkbox in one of my columns which I define as below
<toolkit:DataGrid x:Name="m_PositionsGrid"
CanUserSortColumns="True"
MinHeight="200"
MinWidth="100"
><toolkit:DataGrid.Columns> <PrimitivesUI:DataGridValueColumn Binding="{Binding Path=Time, Mode=OneWay}" IsReadOnly="True" Width="170"/> <toolkit:DataGridTemplateColumn > <toolkit:DataGridTemplateColumn.CellTemplate> <DataTemplate> <CheckBox Click="OnUsedClicked" IsChecked="{Binding Path=Used}" /> </DataTemplate> </toolkit:DataGridTemplateColumn.CellTemplate> </toolkit:DataGridTemplateColumn> </toolkit:DataGrid.Columns> </toolkit:DataGrid>
When I do so , And my datagrid gets populated , I can sort on Time column, but say few of my checkboxes are true and some false, then I would like to sort that column as well, so that all true checkbox gets grouped. I do understand that since we have multiple true or multiple false values so sorting cannot happen , but say I would like it to be: first sort on checkbox column and then sort on time column, so by this way all true checkboxes shall be together and they shall be sorted on secondary field time. But I have no idea whether this can be implemented or not, if yes can somebody please point to the code. Thanks BV
When we add a customized checkbox column to a datagrid in .net (windows application) , the default property allows to check or uncheck the column using a double click. On the first click it selects the column and on the second click the column is either checked or unchecked. To change this default property, we need to handle the click event on grid and modify the selected cell value. For more details.Please check the link below. http://www.mindfiresolutions.com/Checkbox-Column-In-Datagrid-857.php[^]
Cheers, Eliza