在 DataGridView 的行标题中显示行号 [英] Show row number in row header of a DataGridView
本文介绍了在 DataGridView 的行标题中显示行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在 DataGridView
的行标题中显示行号?
Is it possible to show row number in the row header of a DataGridView
?
我正在尝试使用此代码,但不起作用:
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
属性?
Do I have to set some DataGridView
property?
推荐答案
好像没有把它变成字符串.试试
It seems that it doesn't turn it into a string. Try
row.HeaderCell.Value = String.Format("{0}", row.Index + 1);
这篇关于在 DataGridView 的行标题中显示行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文