We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

gridgroupin control cell conditional formating from value from another column

hi i am evaluating ggc. i try to conditionally format a cell based on a value from another cell from the same row.
ie if col a row 5 value >5 then col b row 5 cell backcolor=5


i have somehow managed to do it using QueryCellStyleInfo but the grid crashes after using the field chooser to change the displayed columns

any help woud be greatly appreciated.



3 Replies

SA Solai A L Syncfusion Team December 9, 2015 06:43 AM UTC

Hi Panos,

Thank you for using Syncfusion products.

Instead of using QueryCellInfo event for conditional formatting, you can use the GridConditionalFormatDescriptor. Please refer to the below code example and sample for reference. 

Code Example :


Syncfusion.Windows.Forms.Grid.Grouping.GridConditionalFormatDescriptor gridConditionalFormatDescriptor1 = newSyncfusion.Windows.Forms.Grid.Grouping.GridConditionalFormatDescriptor();

gridConditionalFormatDescriptor1.Appearance.AnyRecordFieldCell.Interior = newSyncfusion.Drawing.BrushInfo(System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(191)))), ((int)(((byte)(52))))));

gridConditionalFormatDescriptor1.Appearance.AnyRecordFieldCell.TextColor = System.Drawing.Color.White;

gridConditionalFormatDescriptor1.Expression = "[CustomerID]  LIKE \'A*\'";

gridConditionalFormatDescriptor1.Name = "ConditionalFormat 1";



Sample :
https://www.syncfusion.com/downloads/support/forum/121387/ze/CS-2110415607

Note :
If the issue is still not resolved, please replicate your issue in this sample and send it to us, so that it would help us provide a prompt solution.

Thanks,

AL.Solai.



PV panos veinoglou December 9, 2015 07:10 AM UTC

Thanks for the reply, but I only want to format one cell


SA Solai A L Syncfusion Team December 10, 2015 10:44 AM UTC

Hi Panos,

Thank you for your update.

We have changed the sample with conditional formatting for the single cell value using the QueryCellInfo event and also tried using the field chooser. The sample is working fine at our end. Could you please replicate the issue scenario in this sample and update us?
Code Example :

   void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e)

        {

           if(e.TableCellIdentity.ColIndex>0 && e.TableCellIdentity.RowIndex>0 && e.Style.Text == "Sales Representative")

           {

               e.Style.BackColor = Color.GreenYellow;

           }

        }
Modified Sample :
https://www.syncfusion.com/downloads/support/forum/121387/ze/CS_(2)161555433

Note : QueryCellInfo event would be triggered frequently. So, using this event for a single condition will not be an appropriate solution. It may affect the performance when a large data is involved.

Thanks,
AL.Solai.


Loader.
Up arrow icon