[英]DataGridView Cell Value Increment
我想將行中單元格的值增加1,我該怎么做? 嘗試了以下內容:
dataGridViewX1.Rows[dataGridViewX1.CurrentRow.Index].Cells[2].Value =+ 1;
(int)(dataGridViewX1[row_index][column_index].Value) += 1
.Value屬於object類型,因此++或+ =不起作用。
嘗試:
int value = (int)dataGridViewX1.Rows[dataGridViewX1.CurrentRow.Index].Cells[2].Value;
dataGridViewX1.Rows[dataGridViewX1.CurrentRow.Index].Cells[2].Value = value + 1;
您不能添加作為Value
的datagridview
是對象類型。 所以你必須使用int.TryParse
來解析這個值(所以如果單元格包含像文本一樣的無效值,解析會失敗,你可以根據你的要求改變行為),然后加1並將其分配回來到細胞。
你也可以使用dataGridViewX1.CurrentRow.Cells[2]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.