How to change value in cell and background of row, based on a checkboxselection

In my datagrid, one column is a checkbox and there are two things that I There are two things I am looking for
1. How do I change the background color for the entire row, based on if the checkbox column BulkUpdate is check or not.
2. How do I uncheck the BulkUpdate checkbox column in each row?

I have attached my project, that has the questions imbedded within

Attachment: SyncfusionsfDatagrid_648eef44.zip

3 Replies 1 reply marked as answer

MA Mohanram Anbukkarasu Syncfusion Team April 6, 2021 07:42 AM UTC

Hi Karla Franke, 

Thanks for contacting Syncfusion support.  

We are unable to load data in the provided sample. It displays messagebox as given below.  

 

However please find the solutions given below for the mentioned queries. 

Query 
Solution 
1. How do I change the background color for the entire row, based on if the checkbox column BulkUpdate is check or not. 
You can achieve this by using QueryRowStyle event a shown in the following code example.  

Code example :  

AddHandler Me.sfDataGrid1.QueryRowStyle, AddressOf SfDataGrid1_QueryRowStyle 
 
Private Sub SfDataGrid1_QueryRowStyle(ByVal sender As Object, ByVal e As Syncfusion.WinForms.DataGrid.Events.QueryRowStyleEventArgs) 
       If e.RowType = RowType.DefaultRow Then 
              If CBool(Me.sfDataGrid1.View.GetPropertyAccessProvider().GetValue(e.RowData, "BulkUpdate")) Then 
                     e.Style.BackColor = Color.Yellow 
              Else 
                     e.Style.BackColor = Color.LightGreen 
              End If 
       End If 
End Sub 


2. How do I uncheck the BulkUpdate checkbox column in each row? 

You can change the check box value of the row when double clicking on it as shown in the following code example.  

Code Example :  

AddHandler Me.sfDataGrid1.CellDoubleClick, AddressOf SfDataGrid1_CellDoubleClick 
 
Private Sub SfDataGrid1_CellDoubleClick(ByVal sender As Object, ByVal e As Syncfusion.WinForms.DataGrid.Events.CellClickEventArgs) 
       If e.DataRow.RowType = RowType.DefaultRow Then 
              Dim bulkUpdateValue = CBool(Me.sfDataGrid1.View.GetPropertyAccessProvider().GetValue(e.DataRow.RowData, "BulkUpdate")) 
              Me.sfDataGrid1.View.GetPropertyAccessProvider().SetValue(e.DataRow.RowData, "BulkUpdate", (Not bulkUpdateValue)) 
       End If 
End Sub 



  

Please let us know if you require further assistance from us.  

Regards, 
Mohanram A. 



Marked as answer

KF Karla Franke April 6, 2021 01:07 PM UTC

I apologize for not attaching a working project.

In regards to the second question "How do I uncheck the BulkUpdate checkbox column in each row? "

Let's say I have 10 rows in my datagrid.
Rows 1, 2 and 3 have the BulkUpdate checkbox column checked.
If I double click in the 6th row, How do I uncheck the BulkUpdate checkbox in rows 1, 2 and 3?  Or how do I uncheck all the rows in my datagrid?
Your example uses e.DataRow.RowData but that only references the row that was double-clicked in. 


MA Mohanram Anbukkarasu Syncfusion Team April 7, 2021 12:29 PM UTC

  
Hi Karla Franke, 

Thanks for the update.  

You can achieve this by setting the BulkUpdate value for all the needed rows as shown in the following code example.  

Code example :  
For Each item In Me.sfDataGrid1.View.Records 
      Dim bulkUpdate = CBool(Me.sfDataGrid1.View.GetPropertyAccessProvider().GetValue(item.Data, "BulkUpdate")) 
      If bulkUpdate Then 
            Me.sfDataGrid1.View.GetPropertyAccessProvider().SetValue(item.Data, "BulkUpdate", False) 
      End If 
Next item 

Please let us know if you require further assistance from us.  

Regards, 
Mohanram A. 


Loader.
Up arrow icon