Category / Section
How to style rows and cells conditionally based on data in GridTreeControl
You can apply the style for the rows and cells based on some conditions by using the QueryCellInfo event like below,
Style for Rows:
C#
void treeGrid_ModelLoaded(object sender, EventArgs e)
{
treeGrid.Model.QueryCellInfo += Model_QueryCellInfo;
}
void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
int nodeindex = treeGrid.InternalGrid.ResolveIndexToColumnIndex(e.Style.ColumnIndex);
if (nodeindex > -1)
{
//Get the node
var node = treeGrid.InternalGrid.GetNodeAtRowIndex(e.Style.RowIndex);
if (node != null)
{
var item = node.Item as EmployeeInfo;
if (item != null)
if (item.EmpID == 1002)
e.Style.Background = Brushes.Red;
else if(item.EmpID==1004)
e.Style.Background = Brushes.Blue;
else if (item.EmpID == 1012)
e.Style.Background = Brushes.Yellow;
else if (item.EmpID == 1005)
e.Style.Background = Brushes.Orange;
}
}
}

Figure 1: Conditional formatting for rows in GridTreeControl
Style for Cells:
C#
void treeGrid_ModelLoaded(object sender, EventArgs e)
{
treeGrid.Model.QueryCellInfo += Model_QueryCellInfo;
}
void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
int nodeindex = treeGrid.InternalGrid.ResolveIndexToColumnIndex(e.Style.ColumnIndex);
if (nodeindex > -1)
{
if (treeGrid.Columns[nodeindex].MappingName != "EmpID")
return;
else
{
//Get the node
var node = treeGrid.InternalGrid.GetNodeAtRowIndex(e.Style.RowIndex);
if (node != null)
{
var item = node.Item as EmployeeInfo;
if (item != null)
if (item.EmpID == 1002)
e.Style.Background = Brushes.Red;
else if (item.EmpID == 1004)
e.Style.Background = Brushes.Blue;
else if (item.EmpID == 1012)
e.Style.Background = Brushes.Yellow;
else if (item.EmpID == 1005)
e.Style.Background = Brushes.Orange;
}
}
}
}

Figure 2: Conditional formatting for cells in GridTreeControl