此代碼必須從 datagridview 讀取值并將它們保存在列表中,但會生成以下錯誤:“System.Windows.Forms.DataGridViewRow”輸入“System.Data.DataRow”。C# 代碼#: List<string> TotaleOreGiornaliere = new List<string>(); int conta = 0; foreach (DataGridViewRow dr in dataGridViewPrincipale.Rows) { TotaleOreGiornaliere.Add(dr.Rows[conta].Cells[2].FormattedValue.ToString()); conta++; }
2 回答

汪汪一只貓
TA貢獻1898條經驗 獲得超8個贊
List<string> TotaleOreGiornaliere = new List<string>();
foreach (DataGridViewRow dr in dataGridView1.Rows)
{
? ?TotaleOreGiornaliere.Add(dr.Cells[2].FormattedValue.ToString());
}
嘗試上面的代碼片段會起作用。
dr.Rows[conta].Cells[2].FormattedValue.ToString()?
這將不起作用,因為 DataGridViewRow 不包含 Rows 屬性

白豬掌柜的
TA貢獻1893條經驗 獲得超10個贊
只需使用 DataRow:
foreach (DataRow dr in dataGridViewPrincipale.Rows) {
TotaleOreGiornaliere.Add(dr.Rows[conta].Cells[2].FormattedValue.ToString());
conta++;
}
- 2 回答
- 0 關注
- 209 瀏覽
添加回答
舉報
0/150
提交
取消