在gridView1的"EndSorting"事件中加入以下代碼:
1private void gridView1_EndSorting(object sender, EventArgs e)
2 {
3 Color clr = gridView1.Appearance.Row.BackColor;
4 foreach (DevExpress.XtraGrid.Columns.GridColumn dc in gridView1.Columns)
5 {
6 if (dc.VisibleIndex == gridView1.SortedColumns[0].VisibleIndex)
7 {
8 dc.AppearanceCell.BackColor = Color.Red;
9 }
10 else
11 {
12 dc.AppearanceCell.BackColor = clr;
13 }
14 }
15 }
2 {
3 Color clr = gridView1.Appearance.Row.BackColor;
4 foreach (DevExpress.XtraGrid.Columns.GridColumn dc in gridView1.Columns)
5 {
6 if (dc.VisibleIndex == gridView1.SortedColumns[0].VisibleIndex)
7 {
8 dc.AppearanceCell.BackColor = Color.Red;
9 }
10 else
11 {
12 dc.AppearanceCell.BackColor = clr;
13 }
14 }
15 }
webfrom:
在DataGrid的SortCommand事件加入以下代碼:
1foreach(DataGridColumn dgc in dg.Columns)
2{
3 if (dgc.SortExpression == e.SortExpression)
4 {
5 dgc.ItemStyle.BackColor = Color.Red;
6 }
7 else
8 {
9 dgc.ItemStyle.BackColor = Color.White;
10 }
11}
2{
3 if (dgc.SortExpression == e.SortExpression)
4 {
5 dgc.ItemStyle.BackColor = Color.Red;
6 }
7 else
8 {
9 dgc.ItemStyle.BackColor = Color.White;
10 }
11}
其中dg是DataGrid的實例,e是SortCommand事件傳入的DataGridSortCommandEventArgs類型參數