This is a migrated thread and some comments may be shown as answers.

Change header text forecolor of sorted column

2 Answers 120 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Web Services
Top achievements
Rank 2
Web Services asked on 03 Jul 2012, 09:37 PM
I'm not seeming to find anywhere where I can change the fore color of only the sorted header field. I'm using custom colors on the sort and I need to change the color of the text but only on the column that's sorted.

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 04 Jul 2012, 04:25 AM
Hello,

In order to change the header color on sorting, try the following code in Prerender event.
C#:
void RadGrid1_PreRender(object sender, EventArgs e)
{
    if (RadGrid1.MasterTableView.SortExpressions.Count > 0)
    {
     foreach (GridSortExpression expression in RadGrid1.MasterTableView.SortExpressions)
     {
       GridHeaderItem headerItem = (GridHeaderItem)RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0];
        headerItem[expression.FieldName].BackColor = System.Drawing.Color.Red;
     }
   }
}
For changing the entire column color on sorting, try setting the following.
aspx:
<SortingSettings SortedBackColor="Red"  />

Thanks,
Shinu.
0
Web Services
Top achievements
Rank 2
answered on 05 Jul 2012, 02:19 PM
I changed backcolor to forecolor as I was trying to change the text color, but it worked perfectly, here's the vb in case anyone else needs it.

Protected Sub clientGrid_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles clientGrid.PreRender
 
    If (clientGrid.MasterTableView.SortExpressions.Count > 0) Then
 
        For Each exp As GridSortExpression In clientGrid.MasterTableView.SortExpressions
 
            Dim headerItem As GridHeaderItem = TryCast(clientGrid.MasterTableView.GetItems(GridItemType.Header)(0), GridHeaderItem)
            headerItem(exp.FieldName).ForeColor = Drawing.Color.White
 
        Next 'for each
 
    End If 'if count > 0
 
End Sub 'prerender
Tags
Grid
Asked by
Web Services
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Web Services
Top achievements
Rank 2
Share this question
or