列值到数组c#
column value to an array c#
我有一列是我的第三列。
单击按钮时,我正在努力将值放入未知数组大小。
int rowCount = dataGridView1.Rows.Count;
string[] Priority = new string[rowCount];
if (rowCount > 1) // only sort if bigger than one line
{
for (int i = 2; i < rowCount; i++)
{
dataGridView1.Rows[i].Cells[2].Value = priority[i]; //put data into row thats been added
}
}
当我尝试多行时,我得到一个 System.IndexOutOfRangeException
,如果我想将一个值添加到数组但我不确定它有什么问题,这很好吗?谢谢
不确定这是否是您的问题,但您实例化为 "Priority"
那么你正在使用 'priority'
可能是在别处命名的 属性?
我同意减一。 i = 2 令人困惑
我是新手,但我认为数组的大小总是有限的。
只是我的想法。
试试这个:
// Modify the value in the first cell of the second row.
this.dataGridView1.Rows[i].Cells[0].Value = "new value";
// The previous line is equivalent to the following line.
this.dataGridView1[i, 2].Value = "new value";
我有一列是我的第三列。
单击按钮时,我正在努力将值放入未知数组大小。
int rowCount = dataGridView1.Rows.Count;
string[] Priority = new string[rowCount];
if (rowCount > 1) // only sort if bigger than one line
{
for (int i = 2; i < rowCount; i++)
{
dataGridView1.Rows[i].Cells[2].Value = priority[i]; //put data into row thats been added
}
}
当我尝试多行时,我得到一个 System.IndexOutOfRangeException
,如果我想将一个值添加到数组但我不确定它有什么问题,这很好吗?谢谢
不确定这是否是您的问题,但您实例化为 "Priority" 那么你正在使用 'priority'
可能是在别处命名的 属性?
我同意减一。 i = 2 令人困惑
我是新手,但我认为数组的大小总是有限的。
只是我的想法。
试试这个:
// Modify the value in the first cell of the second row.
this.dataGridView1.Rows[i].Cells[0].Value = "new value";
// The previous line is equivalent to the following line.
this.dataGridView1[i, 2].Value = "new value";