string[,] Datavalue = new string[GridDelivery.Rows.Count - 1, GridDelivery.Columns.Count];
foreach (DataGridViewRow row in GridDelivery.Rows)
{
foreach (DataGridViewColumn Col in GridDelivery.Columns)
{
// error occurs on this line of code
Datavalue[row.Index, Col.Index] = GridDelivery.Rows[row.Index].Cells[Col.Index].Value.ToString();
}
}
在過去的幾天里,我真的在為此苦苦掙扎,似乎真的無法弄清楚為什么它給了我空值。我使用 datagridview 作為我的輸入來獲取價值可能就是這個原因,如果是,請幫助我找到類似的東西,以便它可以輕松輸入。
在 GridDelivery.Rows 中包含 -1,否則它會讀取最后一行并給出 null,但不知道如何解決此問題。GUI 已鏈接 ==>
在此處輸入影像描述
并在除錯后顯示錯誤
在此處輸入影像描述
uj5u.com熱心網友回復:
嘗試將您的代碼更改為:
string[,] Datavalue = new string[GridDelivery.Rows.Count, GridDelivery.Columns.Count];
foreach (DataGridViewRow row in GridDelivery.Rows)
{
foreach (DataGridViewColumn Col in GridDelivery.Columns)
{
Datavalue[row.Index, Col.Index] = GridDelivery.Rows[row.Index].Cells[Col.Index]?.Value?.ToString();
}
}
我建議閱讀這些文章:
鋸齒狀陣列
空條件運算子
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/517311.html
標籤:C#数据网格视图无效的
上一篇:為什么sFTP指紋在Filezilla中有效,但在復制到C#時卻不能在其他復制的指紋中有?
下一篇:如何斷言XUnit中例外的屬性?
