在一个DataGridView的行标题显示行数行数、标题、DataGridView

2023-09-04 00:14:07 作者:愿你无恙

时它可以显示在的DataGridView 的行标题行号?

Is it possible to show row number in the row header of a DataGridView?

我想这个code,但它不工作:

I'm trying with this code, but it doesn't work:

    private void setRowNumber(DataGridView dgv)
    {
        foreach (DataGridViewRow row in dgv.Rows)
        {
            row.HeaderCell.Value = row.Index + 1;
        }
    }

我是否需要设置一些的DataGridView 属性?

推荐答案

看来,它并没有把它变成一个字符串。 尝试

It seems that it doesn't turn it into a string. Try

row.HeaderCell.Value = String.Format("{0}", row.Index + 1);