[Solved] Problem with Datagrid_CellCheckBoxClick event?

I have a datagrid, after databinding with datatable, I can view my data from the table (it contains checkbox column).
I want to be able to work directly with the checkbox column (meaning I will click directly on the checkbox without selecting the row), I have used this event to determine if the checkbox is checked:

private void sfDataGrid1_CellCheckBoxClick(object sender, CellCheckBoxClickEventArgs e)
{
    if (e.Column.HeaderText == "myCheckboxColumnName" && e.NewValue == Windows.Forms.CheckState.Checked)
    {
     ......
    }
}

However, if the datarow is not selected: e.newvalue will not return a value determine checkbox checked. meaning I always have to select the row before clicking on the checkbox.
What do I need to do to retrieve data just by clicking the checkbox.

4 Replies

TG The GridLock April 28, 2020 12:56 PM UTC

My mistake when not using: e.OldValue != Windows.Forms.CheckState.Checked :((


SS Susmitha Sundar Syncfusion Team April 29, 2020 08:37 AM UTC

Hi GridLock, 
 
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, 
Susmitha S 



SV Shaun Verduyn replied to Susmitha Sundar November 28, 2024 04:11 PM UTC

Hi,

I have a datagrid, after databinding with datatable, I can view my data from the table (it contains checkbox column).I want to be able to work directly with the checkbox column (meaning I will click directly on the checkbox without selecting the row), I have used this event to determine if the checkbox is checked:

SnippetSnippet
private void sfDataGrid1_CellCheckBoxClick(object sender, Syncfusion.WinForms.DataGrid.Events.CellCheckBoxClickEventArgs e)
        {
            var dataRowView = e.Record as DataRowView;
            if (e.Column.HeaderText == "Priority" && e.OldValue != CheckState.Checked)
            {
                dataRowView.Row[1] = true;
            }
            else
            {
                dataRowView.Row[1] = false;
            }
        }

This is not working.

Thanks,

Shaun



SP Sreemon Premkumar Muthukrishnan Syncfusion Team November 29, 2024 04:13 PM UTC

Hi The GridLock,

Thank you for sharing the code snippet with us.

We have reviewed your code snippet and your requirement. Your goal is to determine the status of the checkbox (checked or unchecked) when directly interacting with it.

In the CellCheckBoxClick event, the event argument includes a NewValue property, which reflects the new state of the checkbox after the click. However, in the provided code snippet, you are checking the old value instead. To achieve your requirement, you can use the NewValue property to retrieve the current state of the checkbox.

Code snippet:

 private void SfDataGrid1_CellCheckBoxClick(object sender, Syncfusion.WinForms.DataGrid.Events.CellCheckBoxClickEventArgs e)

 {

     var dataRowView = e.Record as DataRowView;

     if (e.Column.HeaderText == "Is Delivered" && e.NewValue == CheckState.Checked)

     {

         dataRowView.Row[1] = true;

     }

     else

     {

         dataRowView.Row[1] = false;

     }

 }

Output:


If we have misunderstood your requirement, we kindly request you to share additional details, such as a video reference, to help us better understand your needs and provide an accurate solution.

We appreciate your cooperation and look forward to assisting you further.

Regards,
Sreemon Premkumar M.


Loader.
Up arrow icon