请问在C#中怎样获取DataGridView控件中已被选中的行数。 请高手帮忙,谢谢了

2024-12-16 01:58:01
推荐回答(1个)
回答1:

int N=0;
foreach (DataGridViewRow dr in this.dataGridView1.Rows)
{

if (Convert.ToInt16(dr.Cells[5].Value) < Convert.ToInt16(this.comboBox2.Text))
{
dr.Selected = true;
N++;
// this.textBox1.Text = Convert.ToString(dr.Cells[0].Value);
// this.textBox6.Text = Convert.ToString(dr.Cells[1].Value);
// this.comboBox1.Text = Convert.ToString(dr.Cells[2].Value);
// this.textBox3.Text = Convert.ToString(dr.Cells[3].Value);
// this.textBox4.Text = Convert.ToString(dr.Cells[4].Value);
// this.textBox5.Text = Convert.ToString(dr.Cells[5].Value);

}

MessageBox.Show("共有" + N.tostring() + "件餐饮品库存量少于" + this.comboBox2.Text + "件。");