if (dataGridView1.Rows.Count >= 0)
{
int sum = 0;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i].Cells[3].Value.ToString() == "แพ็ค")
{
sum += Convert.ToInt32(dataGridView1.Rows[i].Cells[2].Value);
label1.Text = sum.ToString();
}
}
}
if (dataGridView1.Rows.Count >= 0)
{
int sum = 0;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i].Cells[3].Value.ToString() == "แพ็ค")
{
sum += Convert.ToInt32(dataGridView1.Rows[i].Cells[2].Value);
if (dataGridView1.Rows.Count >= 0)
{
int sum = 0;
for (int i = 0; i <= dataGridView1.Rows.Count -1; i++) // คุณเริ่ม i =0 เลยจำเป็นต้องใส่ <= แต่ถ้าใส่ i=1 ก็ใช้ < ได้ครับ
{
if (dataGridView1.Rows[i].Cells[3].Value.ToString() == "แพ็ค")
{
sum += Convert.ToInt32(dataGridView1.Rows[i].Cells[2].Value);
}
}
label1.Text = sum.ToString();
}