<syncfusion:GridUnBoundColumn MappingName="Closed" SetCellBoundValue="True">
<syncfusion:GridUnBoundColumn.CellTemplate>
<DataTemplate>
<CheckBox HorizontalAlignment="Center" IsChecked="{Binding Value}"
syncfusion:FocusManagerHelper.FocusedElement="True"
VerticalAlignment="Center" Checked="CheckBox_Checked"/>
</DataTemplate>
</syncfusion:GridUnBoundColumn.CellTemplate>
</syncfusion:GridUnBoundColumn> |
public partial class MainWindow : Window
{
Dictionary<object, bool?> checkBoxValues = new Dictionary<object, bool?>();
public MainWindow()
{
InitializeComponent();
this.dataGrid.QueryUnboundColumnValue += DataGrid_QueryUnboundColumnValue;
}
private void DataGrid_QueryUnboundColumnValue(object sender, GridUnboundColumnEventsArgs e)
{
if (e.UnBoundAction == UnBoundActions.QueryData)
{
if (checkBoxValues.ContainsKey(e.Record))
e.Value = checkBoxValues[e.Record];
}
}
private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
var checkBox = sender as CheckBox;
if (checkBox != null && this.dataGrid.CurrentItem != null)
{
if (!checkBoxValues.ContainsKey(this.dataGrid.CurrentItem))
checkBoxValues.Add(this.dataGrid.CurrentItem, checkBox.IsChecked);
checkBoxValues[this.dataGrid.CurrentItem] = checkBox.IsChecked;
this.dataGrid.UpdateUnboundColumn(this.dataGrid.CurrentItem, "Closed");
}
}
} |