winform中如何让datagridview自动显示行号
2个回答
展开全部
public Form1()
{
InitializeComponent();
this.dataGridView1 .RowsAdded+=new DataGridViewRowsAddedEventHandler(dataGridView1_RowsAdded);
}
private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
for (int i = 0; i < e.RowCount; i++)
this.dataGridView1.Rows[e.RowIndex + i].HeaderCell.Value = (e.RowIndex + i + 1).ToString();
}
展开全部
winform中让datagridview自动显示行号代码如下:
private void gvPurchaseOrder_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
using (SolidBrush b = new SolidBrush(this.gvPurchaseOrder.RowHeadersDefaultCellStyle.ForeColor))
{
e.Graphics.DrawString(Convert.ToString(e.RowIndex + 1, CultureInfo.CurrentUICulture),
e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
}
}
private void gvPurchaseOrder_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
using (SolidBrush b = new SolidBrush(this.gvPurchaseOrder.RowHeadersDefaultCellStyle.ForeColor))
{
e.Graphics.DrawString(Convert.ToString(e.RowIndex + 1, CultureInfo.CurrentUICulture),
e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询