dataGridView 中是否有点击后事件。 请教各位。。 Cells[2].Value Cells[3].Value 这个两个在数据库中式 BOOL 值我目前写在 这些 dataGridView1_CellContentClick、dataGridView1_CellClick、dataGridView1_CellEndEdit 等事件里面for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
{
if (this.dataGridView1.CurrentRow.Index == i)
{
if (Convert.ToBoolean(this.dataGridView1.Rows[i].Cells[2].Value) == true)
{
this.dataGridView1.Rows[i].Cells[3].Value = false;
this.dataGridView1.Rows[i].Cells[7].Value = 1;
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.YellowGreen;
}
if (Convert.ToBoolean(this.dataGridView1.Rows[i].Cells[3].Value) == true)
{
this.dataGridView1.Rows[i].Cells[2].Value = false;
this.dataGridView1.Rows[i].Cells[7].Value = 2;
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.YellowGreen;
}
}
}
现在代码中无法 实现及时性 如果我点了 Cells[2],他的Cells[2].Value == true 可是我调试的时候 所有IF 都跳过, 这个我也能理解 因为我点击的时候 Cells[2] Cells[3] 中还没有值当我第二点击的 就能判断到了。我想要的效果就是 单击产生值了以后 去做判断, 请问时候有 dataGridView 中是否有 点击后事件
{
if (this.dataGridView1.CurrentRow.Index == i)
{
if (Convert.ToBoolean(this.dataGridView1.Rows[i].Cells[2].Value) == true)
{
this.dataGridView1.Rows[i].Cells[3].Value = false;
this.dataGridView1.Rows[i].Cells[7].Value = 1;
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.YellowGreen;
}
if (Convert.ToBoolean(this.dataGridView1.Rows[i].Cells[3].Value) == true)
{
this.dataGridView1.Rows[i].Cells[2].Value = false;
this.dataGridView1.Rows[i].Cells[7].Value = 2;
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.YellowGreen;
}
}
}
现在代码中无法 实现及时性 如果我点了 Cells[2],他的Cells[2].Value == true 可是我调试的时候 所有IF 都跳过, 这个我也能理解 因为我点击的时候 Cells[2] Cells[3] 中还没有值当我第二点击的 就能判断到了。我想要的效果就是 单击产生值了以后 去做判断, 请问时候有 dataGridView 中是否有 点击后事件
这是因为点击事件后,selectedValue才会改变。
因此判断哪个被选中的方法需要改变,最简单的可以通过鼠标位置的计算来判断哪行被选中了
重新加载后 就失去了意义 客户要求 键盘 小数字键操作 我实现了现在需要 键盘 鼠标 双操作。 在未跟数据库 打交道的情况下 可以虚拟的 在datagridview1 中 看见是选中了 Cells[2] 或者 Cells[3] 二者只能选其一
/// 不能选择多个顾客去结账
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param> edit by zyl 2011-3-9
private void dgvGuaDan_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
int customer = 0;//免单
if (e.ColumnIndex == 2)
{
if (this.dgvGuaDan.CurrentRow.Cells[2].EditedFormattedValue.ToString() == "True")
{
string accountStyle = dgvGuaDan.CurrentRow.Cells[1].Value.ToString();
for (int i = 0; i < dgvGuaDan.Rows.Count; i++)
{
if (dgvGuaDan.Rows[i].Cells[2].EditedFormattedValue.ToString() == "True")
{
customer = customer + 1;
}
}
if (customer > 1)
{
for (int j = 0; j < dgvGuaDan.Rows.Count; j++)
{
if (!dgvGuaDan.Rows[j].Cells[1].Value.ToString().Equals(accountStyle))
{
dgvGuaDan.Rows[j].Cells[2].Value = false;
}
}
}
}
}
customer = 0; }
(小蕾)谢谢小蕾 你的方法可用。是我想的太复杂了