嗨,我有一個DataGridView未綁定到數據庫的。我僅使用它來插入數據,SQL Server但在插入之前我需要分別第一、第二和第三列的總行數,其中包含 true 和 false。我想分別計算那些具有真實值的列行。我希望有一個人可以幫助我。
1 回答

月關寶盒
TA貢獻1772條經驗 獲得超5個贊
您沒有發布任何代碼,因此無法知道您的網格視圖列是如何配置的。您需要做的是循環遍歷行并測試列的值。例如,如果您的DataGridView變量名為gridView,您可以執行以下操作:
int col1Count = 0;
int col2Count = 0;
int col3Count = 0;
bool cellValue;
foreach ( DataGridViewRow row in gridView.Rows )
{
cellValue = (bool) row.Cells["col1"].Value;
if ( cellValue )
{
++col1Count;
}
cellValue = (bool) row.Cells["col2"].Value;
if ( cellValue )
{
++col2Count;
}
cellValue = (bool) row.Cells["col3"].Value;
if ( cellValue )
{
++col3Count;
}
}
- 1 回答
- 0 關注
- 99 瀏覽
添加回答
舉報
0/150
提交
取消