C# 中dev gridview怎么在最左边显示序号,如图显示

它的属性是在什么地方设置的?

第1个回答  2014-04-29

首先要保证显示RowHeader列,然后在DataGridView的RowPostPaint事件中写如下代码:

private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
    using (SolidBrush b = new SolidBrush(dataGridView1.RowHeadersDefaultCellStyle.ForeColor))
    {
        e.Graphics.DrawString(e.RowIndex.ToString(System.Globalization.CultureInfo.CurrentUICulture), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
    }
}

追问

RowPostPaint事件没找到啊!RowHeader列显示属性在哪儿设置?

追答dataGridView1.RowHeadersVisible = true;//显示行头

本回答被网友采纳
第2个回答  2017-12-19
private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
{
e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
if (e.Info.IsRowIndicator)
{
if (e.RowHandle >= 0)
{
e.Info.DisplayText = (e.RowHandle + 1).ToString();
}
}
}