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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Conditional formatting

Thread ID:





49223 Sep 13,2006 04:34 PM UTC Sep 14,2006 04:05 PM UTC WinForms 3
Tags: GridControl
Asked On September 13, 2006 04:34 PM UTC


I have a GridControl with 3 columns. Cells in column C contains a conditional formula that return only two values: 0 or 1. I want that the format of column B changes depending on the value of column C.

This it is the algorithm:

If C1=1 then B1.ReadOnly=True : B1.BackColor=Gray ....
Else B1.ReadOnly=False : B1.BackColor=White ....

If C2=1 then B2.ReadOnly=True : B2.BackColor=Gray ....
Else B2.ReadOnly=False : B2.BackColor=White ....

If C3=1 then B3.ReadOnly=True : B3.BackColor=Gray ....
Else B3.ReadOnly=False : B3.BackColor=White ....

Something like this already I try:

Private Sub GridControl1_CurrentCellDeactivated(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCurrentCellDeactivatedEventArgs) Handles GridControl1.CurrentCellDeactivated
If e.ColIndex = 2 Then
For i = 1 To GridControl1.RowCount
If GridControl1(i, 3).FormattedText = "1" Then
GridControl1(i, 2).ReadOnly = False
GridControl1(i, 2).BackColor = Color.Gray
GridControl1(i, 2).Text = "NA"
GridControl1(i, 2).ReadOnly = True
GridControl1(i, 2).ReadOnly = False
GridControl1(i, 2).BackColor = Color.White
If GridControl1(i, 2).Text = "NA" Then
GridControl1(i, 2).Text = ""
End If
End If
End If
End Sub

But it does not work well.

I saw that in your Web page you have a sample named "Formatting Cells Based on Criteria", I think that is seemed to that I need, but I not where to find it.

Best Regards,

P.D. I do not speak very well English, it excuses if I am mistaken.


Administrator [Syncfusion]
Replied On September 14, 2006 04:51 AM UTC

Hi Jorge,

To dynamically set style properties on a cell, the PrepareViewStyleInfo event has to handled. We can access the data through Model object in the row and after checking conditions, we can change the style of the row. Below is a code snippet.

Private Sub GridControl1_PrepareViewStyleInfo(ByVal sender As System.Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs) Handles GridControl1.PrepareViewStyleInfo
If e.RowIndex > 0 And e.ColIndex = 2 Then
If GridControl1(e.RowIndex, 3).FormattedText = "1" Then
e.Style.ReadOnly = True
e.Style.BackColor = Color.Gray
e.Style.Text = "NA"
e.Style.ReadOnly = False
e.Style.BackColor = Color.White
If e.Style.Text = "NA" Then
e.Style.Text = ""
End If

End If
End If
End Sub

Here is a modified sample.

Best Regards,

Replied On September 14, 2006 03:38 PM UTC

Thank you for your quick answer,

I think that now I am oriented to the corrected way. Nevertheless, I notice that the PrepareViewStyleInfo event is invocated when the cell receives the focus or when grid is drawn, so the format of the cells not always is updated when the value of column C changes. There is some way to change this behavior?

Thank you for your patient,

Best regards,

Replied On September 14, 2006 04:05 PM UTC

Hi Haneef

I think that I have found the solution, simply I added the following line of code to the event CurrentCellDeactivate:


Is that the best way to do it?

Thank you,


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon