Use a Cell Value to Change the Value of a Different Cell?

In my QueryCellStyle method, I want to query a cell and, if the value meets my criteria, change the appearance or value of a different cell in that row. How can I accomplish this?

Second, my records are instances of a class with many properties, only some of which I display in the grid. Is it possible for me query the value of a non-displayed property in a record and use this data to initiate certain cell modifications?

I am using C#.

Thank you!



1 Reply

VS Vijayarasan Sivanandham Syncfusion Team July 15, 2021 11:38 AM UTC

Hi Tradecode,

Thank you for contacting Syncfusion Support.

Please find answer for your queries below 
Queries 
Solutions 
 
In my QueryCellStyle method, I want to query a cell and, if the value meets my criteria, change the appearance or value of a different cell in that row. How can I accomplish this? 
 

Your requirement can be achieved by customize the QueryCellStyle event in SfDataGrid. Please refer the below code snippet, 
private void SfDataGrid_QueryCellStyle(object sender, Syncfusion.WinForms.DataGrid.Events.QueryCellStyleEventArgs e) 
{ 
            // Style for OrderID column is changed based on the values in CustomerID column 
            if (e.Column.MappingName == "OrderID") 
            { 
                //get the record value by type cast the underline model or business object 
                var record = e.DataRow.RowData as OrderInfo; 
                 
                //check the value  
                if (record != null && record.CustomerID == "ANTON") 
                { 
                    e.Style.BackColor = Color.Coral; 
                    e.Style.TextColor = Color.White; 
                } 
            } 
} 
 
my records are instances of a class with many properties, only some of which I display in the grid. Is it possible for me query the value of a non-displayed property in a record and use this data to initiate certain cell modifications? 
 
 
Your requirement can be achieved by customize the QueryCellStyle event in SfDataGrid. Please refer the below code snippet, 
 
private void SfDataGrid_QueryCellStyle(object sender, Syncfusion.WinForms.DataGrid.Events.QueryCellStyleEventArgs e) 
{             
            // Style for CustomerName column is changed based on the values of a non-displayed property of Country 
            if (e.Column.MappingName == "CustomerName") 
            { 
                //get the record value by type cast the underline model or business object 
                var record = e.DataRow.RowData as OrderInfo; 
 
                //checke the value 
                if (record != null && record.Country == "Mexico") 
                { 
                    e.Style.BackColor = Color.Green; 
                    e.Style.TextColor = Color.Yellow; 
                } 
            } 
}    
 
For more information related to QueryCellStyle, please refer the user guide documentation,

UG Link: https://help.syncfusion.com/windowsforms/datagrid/conditionalstyling 
Please let us know if you have any concerns in this.

Regards,
Vijayarasan S 


Loader.
Up arrow icon