[英]Counting rows on a datagrid and adding it as a new column
以下代碼將向表中添加1個新列,然后使用該行的索引號填充該列中的每一行。
如果您不想以0
開頭,則只需更改int i = 0;
int i = 1;
table.Columns.Add("Book num", typeof(string));
int i = 0;
foreach (DataRow dr in table.Rows)
{
dr["Book num"] = i;
i++;
}
嘗試總行數,
int TotalRows = 0;
for (int i = 0; i < table.Rows.Count; i++)
{
if(i == 0)
{
TotalRows = 1;
}
else
{
TotalRows + = i;
}
string rowNum = table.Rows[i].ToString();
table.Columns.Add("Book num", typeof(string), rowNum);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.