显示行号类
/// <summary> /// GridView 显示行号 设置行号列的宽度 /// </summary> /// <param name="gv">GridView 控件名称</param> /// <param name="width">行号列的宽度 如果为null或为0 默认为30</param> public void DrawRowIndicator(DevExpress.XtraGrid.Views.Grid.GridView gv, int width) { gv.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(gv_CustomDrawRowIndicator); if (width != null) { if (width != 0) { gv.IndicatorWidth = width; } else { gv.IndicatorWidth = 30; } } else { gv.IndicatorWidth = 30; } } //行号设置 private void gv_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e) { if (e.Info.IsRowIndicator && e.RowHandle > -1) { e.Info.DisplayText = (e.RowHandle + 1).ToString(); } }
调用:
DrawRowIndicator(gridView1, 30);
备注:
显示行号可以直接给GridView添加CustomRowIndicator事件 ,即上面的“行号设置”方法
时间: 2024-12-28 12:11:10