bool b = false; for (int i = 0; i < dataGridView1.Rows.Count; i++) { if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue != true) { b = true; break; } } if (b) MessageBox.Show(TT);
版主大人,逻辑反了吧,他是想判断未选中啊,应该是这样: if (!b) MessageBox.Show(TT);
是不是应该这样的哦 DataTable dtShow = new DataTable(); dtShow = (DataTable)this.form1.dataGridView1.DataSource; bool b = false; for (int i = 0; i < dataGridView1.Rows.Count; i++) { if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue == true)//这里把!=改成== { b = true; break; } } if (b) { for (int i = 0; i < dataGridView1.Rows.Count; i++) { if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue == true) //查找被选择的数据行 { string GoodsCode = dataGridView1.Rows[i].Cells["name"].Value.ToString(); string GoodsName = dataGridView1.Rows[i].Cells["password"].Value.ToString(); MessageBox.Show("选择的物品是:" + GoodsName);
} } } else { MessageBox.Show("请选择"); }
版主大人,逻辑反了吧,他是想判断未选中啊,应该是这样: if (!b) MessageBox.Show(TT);
是不是应该这样的哦 DataTable dtShow = new DataTable(); dtShow = (DataTable)this.form1.dataGridView1.DataSource; bool b = false; for (int i = 0; i < dataGridView1.Rows.Count; i++) { if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue == true)//这里把!=改成== { b = true; break; } } if (b) { for (int i = 0; i < dataGridView1.Rows.Count; i++) { if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue == true) //查找被选择的数据行 { string GoodsCode = dataGridView1.Rows[i].Cells["name"].Value.ToString(); string GoodsName = dataGridView1.Rows[i].Cells["password"].Value.ToString(); MessageBox.Show("选择的物品是:" + GoodsName);
} } } else { MessageBox.Show("请选择"); }
是不是应该这样的哦 DataTable dtShow = new DataTable(); dtShow = (DataTable)this.form1.dataGridView1.DataSource; bool b = false; for (int i = 0; i < dataGridView1.Rows.Count; i++) { if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue == true)//这里把!=改成== { b = true; break; } } if (b) { for (int i = 0; i < dataGridView1.Rows.Count; i++) { if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue == true) //查找被选择的数据行 { string GoodsCode = dataGridView1.Rows[i].Cells["name"].Value.ToString(); string GoodsName = dataGridView1.Rows[i].Cells["password"].Value.ToString(); MessageBox.Show("选择的物品是:" + GoodsName);
} } } else { MessageBox.Show("请选择"); }
恩,对了。自己试一把就知道了
bool b = false; for (int i = 0; i < dataGridView1.Rows.Count; i++) { if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue == true) { b = true; break; } } if (!b) MessageBox.Show("请选择!");
MessageBox.Show(TT);
bool b = false;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue == true)//这里把!=改成==
{
b = true;
break;
}
} if (b)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue == true) //查找被选择的数据行
{
string GoodsCode = dataGridView1.Rows[i].Cells["name"].Value.ToString();
string GoodsName = dataGridView1.Rows[i].Cells["password"].Value.ToString();
MessageBox.Show("选择的物品是:" + GoodsName);
}
}
}
else
{
MessageBox.Show("请选择"); }
MessageBox.Show(TT);
是不是应该这样的哦 DataTable dtShow = new DataTable(); dtShow = (DataTable)this.form1.dataGridView1.DataSource;
bool b = false;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue == true)//这里把!=改成==
{
b = true;
break;
}
} if (b)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue == true) //查找被选择的数据行
{
string GoodsCode = dataGridView1.Rows[i].Cells["name"].Value.ToString();
string GoodsName = dataGridView1.Rows[i].Cells["password"].Value.ToString();
MessageBox.Show("选择的物品是:" + GoodsName);
}
}
}
else
{
MessageBox.Show("请选择"); }
bool b = false;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue == true)//这里把!=改成==
{
b = true;
break;
}
} if (b)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue == true) //查找被选择的数据行
{
string GoodsCode = dataGridView1.Rows[i].Cells["name"].Value.ToString();
string GoodsName = dataGridView1.Rows[i].Cells["password"].Value.ToString();
MessageBox.Show("选择的物品是:" + GoodsName);
}
}
}
else
{
MessageBox.Show("请选择"); }
恩,对了。自己试一把就知道了
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue == true)
{
b = true;
break;
}
}
if (!b)
MessageBox.Show("请选择!");