DevExpress GridControl 显示行号、设置行号宽

显示行号类

  /// <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事件 ,即上面的“行号设置”方法

版权声明:本文为博主原创文章,未经博主允许不得转载。

上一篇:使用javascript实现在页面打印的效果的三种方式


下一篇:Python+PyCharm的一些基本设置:安装使用、注册码、显示行号、字体大小和快捷键等常用设置