Category / Section
How to provide custom color for particular cell in OLAP Grid?
1 min read
You can set custom color for a particular cell in the OLAP Grid using the following code example at sample level.
C#
this.OlapGrid1.QueryCellInfo += new EventHandler<CellInfoEventArgs>(OlapGrid1_QueryCellInfo); void OlapGrid1_QueryCellInfo(object sender, CellInfoEventArgs e) { PivotGridCell td = e.Cell; if (td.Text.Contains("$")) { double val = 0; string text = td.Text.Replace('$', ' ').TrimEnd(' '); if (Double.TryParse(text, out val)) { if (val < 40) { td.ForeColor = Color.Green; } else if (val >=40) { td.ForeColor = Color.Red; } } } }
VB
Me.OlapGrid1.QueryCellInfo += New EventHandler<CellInfoEventArgs>(OlapGrid1_QueryCellInfo) Private Sub OlapGrid1_QueryCellInfo(ByVal sender As Object, ByVal e As CellInfoEventArgs) Dim td As PivotGridCell = e.Cell If td.Text.Contains("$") Then Dim val As Double = 0 Dim text As String = td.Text.Replace("$"c," "c).TrimEnd(" "c) If Double.TryParse(text,out val) Then If val < 40 Then td.ForeColor = Color.Green Else If val >=40 Then td.ForeColor = Color.Red End If End If End If End Sub