GridTemplateColumn is dynamically added to
SfDataGrid
. This GridTemplateColumn.CellTemplate is bound to Checkbox control. My data is bound to this SfDataGrid. This grid has few more columns too.
On Editing other columns CurrentCellBeginEdit triggers. But on check/uncheck of this checkbox column, this event doesnt fire.
Tried associating a 'Click' event to the the checkbox and also 'CurrentCellValueChanged' event to the SfDataGrid. No luck.
Hi Priya,
You
are using the CheckBoc as a CellTemplate element in the GridTemplateColumn. In
this case, the Editing related events (CurrentCellValueChanged, CurrentCellBeginEdit) do not get the
notifications and are raised. If you need to raise these events for your scenario,
then you should use EditTemplate. Our SfDataGrid has the In-built GridCheckBoxColumn. With
this, you can get a notification while changing the checkbox value by using
the CurrentCellValueChanged event. For more information related to GridCheckBoxColumn,
please refer to the below user guide documentation link,
UG Link: https://help.syncfusion.com/wpf/datagrid/column-types#gridcheckboxcolumn
For more information related to the CurrentCellValueChanged event, please refer to the below knowledge base documentation link,
Regards,
Dhanasekar M.
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Thanks for the response.
My requirement restrict to use only 'GridTemplateColumn'.
defined the below datatemplate in xaml file.
<DataTemplate x:Key="chkTest">
<CheckBox IsChecked="{Binding Path=Test, Mode=TwoWay}" HorizontalAlignment="Center"
VerticalAlignment="Center" IsEnabled="True"></CheckBox>
</DataTemplate>
Below code is associated to AutoGeneratingColumn method.
GridTemplateColumn checkBoxControl = new GridTemplateColumn();
checkBoxControl.EditTemplate = Resources["chkTest"] as DataTemplate;
checkBoxControl.MappingName = "Test";
checkBoxControl.HeaderText = "Test";
checkBoxControl.ColumnSizer = GridLengthUnitType.None;
dgMain.RefreshColumns();
e.Column = checkBoxControl;
After changing CellTemplate to EditTemplate,it triggers the change event . But now onload, i dont see the checkbox itself in the column. After i doubleclick(edit mode)i can see the checkbox with checked/unchecked according the DB and also allows edit.
Why is the checkbox(with DB bindings) not visible on the grid load.Currently it displays this column with blank data until its editt
Hi Priya,
We regret the inconvenience caused,
You have used the EditTemplate alone that’s why the CellElement does not show in the initial loading. You can overcome this by using the CellTemplate and the EditTemplate shown below,
XAML:
<!-- Here you can define the cell template as not editable
using CheckBox's IsEnabled as false. --> <CheckBox IsEnabled="False" HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding Path=Status , Mode=TwoWay}" /> </DataTemplate> <DataTemplate x:Key="editTemplate"> <CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding Path=Status , Mode=TwoWay}" /> </DataTemplate> |
C#:
this.datagrid.AutoGeneratingColumn += datagrid_AutoGeneratingColumn;
private void datagrid_AutoGeneratingColumn(object sender, AutoGeneratingColumnArgs e) { if (e.Column.MappingName == "Status") { if (e.Column is GridCheckBoxColumn) { e.Column = new GridTemplateColumn() { MappingName = "Status", HeaderText = "Status" , CellTemplate = App.Current.Resources["cellTemplate"] as DataTemplate , EditTemplate = App.Current.Resources["editTemplate"] as DataTemplate }; } } } |
For more information related to changing the column type, please refer to the below user guide documentation link,
UG Link: https://help.syncfusion.com/wpf/datagrid/columns#changing-column-type
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Hi Dhanasekar ,
thanks....it worked....:)
Priya,
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help.