Articles in this section
Category / Section

How to set the text color that appears in the WinForms GridControl cell?

Apply text color


The WinForms GridControl uses the TextColor property of the cell’s style to set it to the Color value. In the given sample, the TextColor is applied for a particular row or column or cell or a range of cells.

 

Using GridModel

//sets the text to the particular row
gridControl1.RowStyles[3].Text = "Have";

//sets the textcolor to the particular cell
gridControl1[3, 2].TextColor = Color.Red;

//sets the textcolor for range of cells
GridStyleInfo style = new GridStyleInfo();

style.TextColor = Color.Red;
this.gridControl1.ChangeCells(GridRangeInfo.Cells(3,3,2,2), style);
'sets the text to the particular row
gridControl1.RowStyles(3).Text = "Have"

'sets the textcolor to the particular cell
gridControl1(3, 2).TextColor = Color.Red

'sets the textcolor for range of cells
Dim style As New GridStyleInfo()

style.TextColor = Color.Red
Me.gridControl1.ChangeCells(GridRangeInfo.Cells(3,3,2,2), style)

By using the QueryCellInfo Event

void gridControl1_QueryCellInfo(object sender, Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs e)
{
 //sets the text to the particular row
 if (e.RowIndex == 3 && e.ColIndex > 0)
  e.Style.Text = "Have";

 //sets the textcolor to the particular cell
 if (e.RowIndex == 3 && e.ColIndex ==2)
  e.Style.TextColor = Color.Red;
}
Private Sub gridControl1_QueryCellInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs)
 'sets the text to the particular row
 If e.RowIndex = 3 AndAlso e.ColIndex > 0 Then
  e.Style.Text = "Have"
 End If

 'sets the textcolor to the particular cell
 If e.RowIndex = 3 AndAlso e.ColIndex =2 Then
  e.Style.TextColor = Color.Red
 End If
End Sub

After applying the TextColor properties, the Grid is shown as follows,

Set the text color in a grid cell


Figure
1: Set the text color 

Samples:

C#: TextColor

VB: TextColor

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied