做了一个WinForm的程序!C#中如何在dataGridView控件中添加行号,就是在每行的最前面显示行号!

[复制链接]
查看11 | 回复5 | 2011-3-18 12:13:45 | 显示全部楼层 |阅读模式
方法一:网上最常见的做法是用DataGridView的RowPostPaint事件在RowHeaderCell中绘制行号: RowPostPaint
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
try
{
//添加行号
SolidBrush v_SolidBrush = new SolidBrush(dataGridView1.RowHead
回复

使用道具 举报

千问 | 2011-3-18 12:13:45 | 显示全部楼层
在控件的 RowPostPaint的方法中添加如下函数即可/// /// datagridview显示行号/// /// dataGridView名 /// RowPostPaint方法中的那个e
回复

使用道具 举报

千问 | 2011-3-18 12:13:45 | 显示全部楼层
///
/// 添加行号
///
///
///
private void dataGridViewX1_RowPos
回复

使用道具 举报

千问 | 2011-3-18 12:13:45 | 显示全部楼层
foreach (DataGridViewRow row in dataGridView.Rows)
{
if (row.IsNewRow) continue;
row.HeaderCell.Value = "Row " + rowNumber;
rowNumber = rowNumber +
回复

使用道具 举报

千问 | 2011-3-18 12:13:45 | 显示全部楼层
for(int i = 1; i <= datagridview.rows.count; i++){
this.datagridview.rows[0][0] = i;}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行