添加行第二列ONLY - 填充使用for循环数据 [英] Adding rows to second column ONLY - populating data using a for loop

查看:100
本文介绍了添加行第二列ONLY - 填充使用for循环数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计算使用基于阅读多少条记录已经已经打开的文件的for循环行我想在我的第二列的数量。我已经研究并尝试各种解决方案,但没有工作,但它似乎很简单。下面是我当前的代码,我检索文件的长度,做一个快速的总和,进入一个for循环的地方(目前)我只能以填充第一列。

I calculate the amount of rows I want to have in my second column using a for loop based on reading how many records a file has that has been opened. I have researched and tried various solutions but nothing works, yet it seems so simple. Below is my current code where I retrieve the file's length and do a quick sum, entering a for loop where (at the moment) I am only able to populate the first column.

long Count = 1;
FileInfo Fi = new FileInfo(file);
long sum = (Fi.Length / 1024) - Count;

for (int i = 0; i < sum; i++)
{
    DataGridView1.Rows.Add(Count++);
}



我不知道怎么做,但我知道上面的代码增加在默认情况下的第一列 - 我不知道如何修改它。我知道是:

I'm not sure how to do it but I know the above code adds to the first column by default - I don't know how to modify it. I know by:

DataGridView1.Rows.Add("a","b");



...在'B'值显示在第二列,但我不希望在第一,其中A是。

... The 'b' value is displayed in the second column, but I don't want anything for now in the first where 'a' is.

我已经看过的插入有一列的DataGridView C#行,但它关系到合并列,再说一次,我不想这样。

I have looked at insert a row with one column datagridview c# but it is related to merging columns, again, I don't want this.

DataGridView1.Rows.Add("",Count++);

作品在一定程度上,而不是做正确的方式。我将在稍后将数据添加到第一列。

Works to an extent, but is not the right way to do it. I'm going to be adding data to the first column later on.

推荐答案

如果你想忽略第一个值列,只需添加 DBNull.Value ,例如:

If you want to omit the value for the first column, just add null or DBNull.Value, e.g.:

DataGridView1.Rows.Add(DBNull.Value, Count++);

此方式,而第二列包含<$ C $的值的第一列将是空C>计数。

This way, the first column will be empty while the second columns contains the value of Count.

这篇关于添加行第二列ONLY - 填充使用for循环数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆