现在的位置: 首页 > 综合 > 正文

gridControl选中某列进行排序时,怎么能让那列高亮显示

2013年12月03日 ⁄ 综合 ⁄ 共 866字 ⁄ 字号 评论关闭

winform:

首先捕获"EndSorting"事件,然后在其中加入以下代码:

  private void gridView_EndSorting(object sender, EventArgs e)
        {

            Color clr = gridView.Appearance.Row.BackColor;
            foreach (DevExpress.XtraGrid.Columns.GridColumn dc in gridView.Columns)
            {
                if (dc.VisibleIndex == gridView1.SortedColumns[0].VisibleIndex)
                {
                    dc.AppearanceCell.BackColor = Color.Red;
                }
                else
                {
                    dc.AppearanceCell.BackColor = clr;
                }
            }
        }

其中的"gridView"是"DevExpress.XtraGrid.Views.Grid.GridView"类型实例

webfrom:

在DataGrid的SortCommand事件加入以下代码:

foreach(DataGridColumn dgc in dg.Columns)
{
 if (dgc.SortExpression == e.SortExpression)
 {
  dgc.ItemStyle.BackColor = Color.Red;
 }
 else
 {
  dgc.ItemStyle.BackColor = Color.White;
 }
}

其中dg是DataGrid的实例,e是SortCommand事件传入的DataGridSortCommandEventArgs类型参数
 

抱歉!评论已关闭.