我試圖計算datagridview中名爲QTY的列的總數。 但我不知道。我的代碼如下。請問你能幫幫我嗎? Datagridview列總數
public int RowCount { get; set; }
[BrowsableAttribute(false)]
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
private void UpdateLabelText()
{
int QtyTotal = 0;
int counter;
// Iterate through all the rows and sum up the appropriate columns.
for (counter = 0; counter < (dataGridView1.Rows.Count);
counter++)
{
if (dataGridView1.Rows[counter].Cells["Qty"].Value
!= null)
{
if (dataGridView1.Rows[counter].
Cells["Qty"].Value.ToString().Length != 0)
{
QtyTotal += int.Parse(dataGridView1.Rows[counter].
Cells["Qty"].Value.ToString());
}
}
}
// Set the labels to reflect the current state of the DataGridView.
label17.Text = "Qty Total: " + QtyTotal.ToString();
}
什麼是與代碼的問題?異常,意外的結果? – Pikoh
總共未顯示標籤17 – Bahadir
它給出了預期錯誤 – Bahadir