1.girdView在第一列显示行号
调整第一列的宽度 gridView1.IndicatorWidth = 40;
View Code
1 private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
2 {
3 if (e.Info.IsRowIndicator && e.RowHandle >= 0)
4 {
5 e.Info.DisplayText = e.RowHandle.ToString();
6 }
7 }
2. 点击 gridView 列的单击事件获取自定列信息
View Code
1 private void gridControl1_Click(object sender, EventArgs e)
2 {
3 if (gridView1.GetFocusedRow() != null)
4 {
5 string name = "";
6 foreach (int rowId in gridView1.GetSelectedRows())
7 {
8 foreach (DevExpress.XtraGrid.Columns.GridColumn col in gridView1.VisibleColumns)
9 {
10
11 name += col.Caption+":"+gridView1.GetRowCellValue(rowId, col).ToString()+"\n";
12
13 }
14
15 }
16 DevExpress.XtraEditors.XtraMessageBox.Show(name);
17 }
18 }
3.根据指定条件设置单元格字体前景色
View Code
1 private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
2 {
3 if (e.CellValue.ToString().Length > 0)
4 {
5 if (e.Column.GetCaption() == "金额" && Convert.ToDouble(e.CellValue) < 100000)
6 {
7 e.Appearance.ForeColor = Color.Red;
8 e.Appearance.BackColor = Color.Yellow;
9 }
10 }
11 }
4. 显示的数据隔行斑马线显示方式
需要将 gridview1的sOptionsView——EnableAppearanceEvenRow/EnableAppearanceOddRow 两个属性设为 True( 默认为 false) ,然后再设置 Appearance 里 EvenRow 和 OddRow 颜色就可以了。