简体   繁体   English

DataGridView ArgumentOutOfRangeException C#

[英]DataGridView ArgumentOutOfRangeException C#

I'm working with a DataGridView but sometimes when I try to insert a value give me the error ArgumentOutOfRangeException .我正在使用 DataGridView 但有时当我尝试插入一个值时会给我错误ArgumentOutOfRangeException

For example:例如:

getMaterialesInforme[2, 1].Value = Convert.ToInt32(sumaMP).ToString();

(getMaterialesInforme is a DataGridView) (getMaterialesInforme 是一个 DataGridView)

This error is because cell [2, 1] doesn't exist so is there a way to create this cell before insert the value?这个错误是因为单元格 [2, 1] 不存在所以有没有办法在插入值之前创建这个单元格? and even better, is there a way to create a DataGridView for example from the cell [0, 0] to cell [40, 10]甚至更好的是,有没有办法创建一个 DataGridView 例如从单元格 [0, 0] 到单元格 [40, 10]

Thanks in advance!提前致谢!

Try this:尝试这个:

for(int i = 0; i <= 40; i++)
{
    getMaterialesInforme.Columns.Add($"Col{i}", $"Col{i}");
}

for (int i = 0; i <= 10; i++)
{
    getMaterialesInforme.Rows.Add();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM