如何为datagridview加上序号

时间: 发布人:f4e7ef

如何为datagridview加上序号

已解决问题

谷歌f4e7ef用户在提交了关于“电影天堂如何为datagridview加上序号”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-11-25T20:35:05。希望大家能够帮助她。

详细问题描述及疑问:期待您的答案,你就是当代的活雷锋,太感谢了 !

希望以下的回答,能够帮助你。

第1个回答

用户名:搞基的圣贤0597  

你可以重写DataGridView的OnR站尔陈权owPostPaint方法或者直接在DataG来自ridView的RowPostPaint事件里写,如下(重写DataGridView的OnRowPostPaint方法)

usingSystem;

usingSystem.Text;

usingSystem.Windows.Forms;

usingSystem.Drawing;

namespaceTest

{

classDataGridViewEx:DataGridView

{

S问答olidBrushsolidBrush;

publicDataGridViewEx()

{

solidBrush=newSolidB也rush(this.Rowh**eadersDefaultCellStyle.F土析oreColor);

}

protectedoverridevoidOnRowPostPaint(DataGridViewRowPostPaintEventArgse益哪让小)

{

e.Graphics.DrawString((e.RowIndex+1).ToString(),e.InheritedRowStyle.Font,solidBrush,e.RowBounds.Location.X+15,e.RowBounds.L敌做激ocation.Y+5);

base.OnRowPost践者裂时半源材Paint(e);

}

}

}