博客园  :: 首页  :: 新随笔  :: 联系 :: 管理

GridControl 使用技巧

Posted on 2009-08-03 13:26  codingsilence  阅读(281)  评论(0编辑  收藏  举报


以下代码已经有好多人写过,还望各位多多指教

我只不过是整理了一下在我使用过程中的比较熟悉的,在以后的使用过程中会继续添加

1.gridView 奇行与偶行交替变色

this.gridView1.OptionsView.EnableAppearanceEvenRow = true;
this.gridView1.OptionsView.EnableAppearanceOddRow = true;

this.gridView1.Appearance.EvenRow.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
this.gridView1.Appearance.EvenRow.Options.UseBackColor = true;
this.gridView1.Appearance.OddRow.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
this.gridView1.Appearance.OddRow.Options.UseBackColor = true;
2.girdView在第一列显示行号

//调整第一列的宽度
this.gridView1.IndicatorWidth = 40;
//添加监听事件
this.gridView1.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(this.gridView1_CustomDrawRowIndicator);
//在非类里这段代码
private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
        ...{
            if (e.Info.IsRowIndicator && e.RowHandle >= 0)
            ...{
                e.Info.DisplayText = Convert.ToString(Convert.ToInt32(e.RowHandle.ToString())+1);
            }
        }
3.

GridControl 選中某列進行排序時,怎麼能讓那列高亮顯示
winform:


在gridView1的"EndSorting"事件中加入以下代碼:


private void gridView1_EndSorting(object sender, EventArgs e)
        ...{
            Color clr = gridView1.Appearance.Row.BackColor;
            foreach (DevExpress.XtraGrid.Columns.GridColumn dc in gridView1.Columns)
            ...{
                if (dc.VisibleIndex == gridView1.SortedColumns[0].VisibleIndex)
                ...{
                    dc.AppearanceCell.BackColor = Color.Red;
                }
                else
                ...{
                    dc.AppearanceCell.BackColor = clr;
                }
           }
       }
webfrom:

在DataGrid的SortCommand事件加入以下代碼:
其中dg是DataGrid的實例,e是SortCommand事件傳入的DataGridSortCommandEventArgs類型參數

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

去掉GridControl控件上面的
Drag a column header here to group by that column
 
Options/OptionsView/ShowGroupPanel      True----->False