Change Value GridCheckBoxColumn

I have 2 column of type GridCheckBoxColumn (AllowCheckBoxOnHeader=true) in an SfDataGrid, 

How Can I Change the value of 2nd Checkbox Column(Header and Detail)  when first checkbox is Checked.
vvItem
vvItem 1
vvItem 2

Thanks.


6 Replies 1 reply marked as answer

DM Dhanasekar Mohanraj Syncfusion Team November 16, 2020 10:42 AM UTC

Hi Sessame,

 
Thank you for using Syncfusion Controls.

 
You can achieve your requirement by SfDataGrid.CellCheckBoxClick and SfDataGrid.CurrentCellActivating events like below, 
this.sfDataGrid1.CellCheckBoxClick += sfDataGrid1_CellCheckBoxClick; 
this.sfDataGrid1.CurrentCellActivating += sfDataGrid1_CurrentCellActivating; 
private void sfDataGrid1_CurrentCellActivating(object sender, CurrentCellActivatingEventArgs e) 
{ 
    if (e.DataColumn.GridColumn.MappingName == "IsClosed1") 
        e.Cancel = true; 
} 
 
private void sfDataGrid1_CellCheckBoxClick(object sender, CellCheckBoxClickEventArgs e) 
{ 
    if (e.Column.MappingName == "IsClosed1") 
        e.Cancel = true; 
 
    if (e.Column.MappingName == "IsClosed" && e.Record != null ) 
    { 
        (e.Record as OrderInfo).IsClosed1 = e.NewValue == CheckState.Checked; 
    } 
} 

We have prepared the sample for the same,

 
 
Please refer the below KB for more information’s,

 
 
Regards,
Dhanasekar Mohanraj. 


Marked as answer

SE Sessame replied to Dhanasekar Mohanraj November 17, 2020 10:28 AM UTC

Hi Sessame,

 
Thank you for using Syncfusion Controls.

 
You can achieve your requirement by SfDataGrid.CellCheckBoxClick and SfDataGrid.CurrentCellActivating events like below, 
this.sfDataGrid1.CellCheckBoxClick += sfDataGrid1_CellCheckBoxClick; 
this.sfDataGrid1.CurrentCellActivating += sfDataGrid1_CurrentCellActivating; 
private void sfDataGrid1_CurrentCellActivating(object sender, CurrentCellActivatingEventArgs e) 
{ 
    if (e.DataColumn.GridColumn.MappingName == "IsClosed1") 
        e.Cancel = true; 
} 
 
private void sfDataGrid1_CellCheckBoxClick(object sender, CellCheckBoxClickEventArgs e) 
{ 
    if (e.Column.MappingName == "IsClosed1") 
        e.Cancel = true; 
 
    if (e.Column.MappingName == "IsClosed" && e.Record != null ) 
    { 
        (e.Record as OrderInfo).IsClosed1 = e.NewValue == CheckState.Checked; 
    } 
} 

We have prepared the sample for the same,

 
 
Please refer the below KB for more information’s,

 
 
Regards,
Dhanasekar Mohanraj. 


Thanks for reply.
More question.

I have AllowCheckBoxOnHeader = true and Master Detail View.

How can i change the value of  CheckboxHeader(No) in 2nd View to Unchecked When 1st ChecboxHeader(Yes) Clicked. 
Note : The Value of CheckboxHeader.

Thanks





DM Dhanasekar Mohanraj Syncfusion Team November 18, 2020 12:16 PM UTC

Hi Sessame,

 
Thank you for your response.

 
Current we are checking on this, we will validate and update you the details on November 20, 2020.

 
We appreciate your patience until then.

 
Regards,
Dhanasekar Mohanraj. 



DM Dhanasekar Mohanraj Syncfusion Team November 20, 2020 03:00 PM UTC

Hi sessame,

 
Thank you for your patience.

 
You can achieve your requirement by setting the HeaderState of the CheckBoxColumn like below, 
FirstLevelNestedGrid.CellCheckBoxClick += FirstLevelNestedGrid_CellCheckBoxClick; 
FirstLevelNestedGrid.CurrentCellActivating += FirstLevelNestedGrid_CurrentCellActivating; 

private void FirstLevelNestedGrid_CurrentCellActivating(object sender, Syncfusion.WinForms.DataGrid.Events.CurrentCellActivatingEventArgs e) 
{ 
    if (e.DataColumn.GridColumn.MappingName == "IsClosed1") 
        e.Cancel = true; 
} 
 
private void FirstLevelNestedGrid_CellCheckBoxClick(object sender, Syncfusion.WinForms.DataGrid.Events.CellCheckBoxClickEventArgs e) 
{ 
    var records = ((e.OriginalSender as DetailsViewDataGrid).DataSource) as List<OrderDetails>; 
    var grid = e.OriginalSender as DetailsViewDataGrid; 
    if (e.Record == null && e.Column.MappingName == "IsClosed") 
    { 
        if (e.NewValue.ToString() == "Checked") 
        { 
            (grid.Columns["IsClosed1"] as GridCheckBoxColumn).GetType().GetProperty("HeaderState", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(grid.Columns["IsClosed1"] as GridCheckBoxColumn, CheckState.Checked); 
        } 
        else 
        { 
            (grid.Columns["IsClosed1"] as GridCheckBoxColumn).GetType().GetProperty("HeaderState", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(grid.Columns["IsClosed1"] as GridCheckBoxColumn, CheckState.Unchecked); 
        } 
 
        for (int i = 0; i < records.Count; i++) 
        { 
            if (e.NewValue.ToString() == "Checked") 
            { 
                (records[i] as OrderDetails).IsClosed1 = true; 
            } 
            else 
            { 
                (records[i] as OrderDetails).IsClosed1 = false; 
            } 
        } 
    } 
    if (e.Column.MappingName == "IsClosed1") 
        e.Cancel = true; 
 
    if (e.Column.MappingName == "IsClosed" && e.Record != null) 
    { 
        (e.Record as OrderDetails).IsClosed1 = e.NewValue == CheckState.Checked; 
    } 
 
} 

We have prepared the sample for the same,

 
 
We hope it helps, please let us know if you need further assistance.

 
Regards,
Dhanasekar Mohanraj. 



SE Sessame replied to Dhanasekar Mohanraj November 22, 2020 05:24 PM UTC

Hi sessame,

 
Thank you for your patience.

 
You can achieve your requirement by setting the HeaderState of the CheckBoxColumn like below, 
FirstLevelNestedGrid.CellCheckBoxClick += FirstLevelNestedGrid_CellCheckBoxClick; 
FirstLevelNestedGrid.CurrentCellActivating += FirstLevelNestedGrid_CurrentCellActivating; 

private void FirstLevelNestedGrid_CurrentCellActivating(object sender, Syncfusion.WinForms.DataGrid.Events.CurrentCellActivatingEventArgs e) 
{ 
    if (e.DataColumn.GridColumn.MappingName == "IsClosed1") 
        e.Cancel = true; 
} 
 
private void FirstLevelNestedGrid_CellCheckBoxClick(object sender, Syncfusion.WinForms.DataGrid.Events.CellCheckBoxClickEventArgs e) 
{ 
    var records = ((e.OriginalSender as DetailsViewDataGrid).DataSource) as List<OrderDetails>; 
    var grid = e.OriginalSender as DetailsViewDataGrid; 
    if (e.Record == null && e.Column.MappingName == "IsClosed") 
    { 
        if (e.NewValue.ToString() == "Checked") 
        { 
            (grid.Columns["IsClosed1"] as GridCheckBoxColumn).GetType().GetProperty("HeaderState", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(grid.Columns["IsClosed1"] as GridCheckBoxColumn, CheckState.Checked); 
        } 
        else 
        { 
            (grid.Columns["IsClosed1"] as GridCheckBoxColumn).GetType().GetProperty("HeaderState", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(grid.Columns["IsClosed1"] as GridCheckBoxColumn, CheckState.Unchecked); 
        } 
 
        for (int i = 0; i < records.Count; i++) 
        { 
            if (e.NewValue.ToString() == "Checked") 
            { 
                (records[i] as OrderDetails).IsClosed1 = true; 
            } 
            else 
            { 
                (records[i] as OrderDetails).IsClosed1 = false; 
            } 
        } 
    } 
    if (e.Column.MappingName == "IsClosed1") 
        e.Cancel = true; 
 
    if (e.Column.MappingName == "IsClosed" && e.Record != null) 
    { 
        (e.Record as OrderDetails).IsClosed1 = e.NewValue == CheckState.Checked; 
    } 
 
} 

We have prepared the sample for the same,

 
 
We hope it helps, please let us know if you need further assistance.

 
Regards,
Dhanasekar Mohanraj. 


It work perfectly now, thank you very much.


VS Vijayarasan Sivanandham Syncfusion Team November 23, 2020 05:28 AM UTC

Hi Sessame, 
 
Thanks for the update. 
 
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 you😊. 
 
Regards, 
Vijayarasan S 


Loader.
Up arrow icon