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 中是否有 点击后事件

解决方案 »

  1.   

    把datagridview1的EditMode属性修改为EditonEnter,然后用dataGridView1_CellClick事件,
      

  2.   

    单击产生值了以后 去做判断 单击产生的是什么值?数据库里的数据不是已经绑定到datagridview上了吗?
      

  3.   

    理解楼主的意思了。
    这是因为点击事件后,selectedValue才会改变。
    因此判断哪个被选中的方法需要改变,最简单的可以通过鼠标位置的计算来判断哪行被选中了
      

  4.   


    重新加载后 就失去了意义   客户要求 键盘 小数字键操作  我实现了现在需要  键盘   鼠标 双操作。   在未跟数据库 打交道的情况下  可以虚拟的 在datagridview1 中 看见是选中了  Cells[2] 或者 Cells[3]  二者只能选其一
      

  5.   

    目前 数据库中的是给客户看见也就 一个未选定 checkBox 直观感觉而已  其实已经有值了  都是 False就是当  点击的  时候 值为 true  
      

  6.   

    这是我曾做的一个例子,你可以参考下。应该能实现你要的效果。这个例子是一个消费列表去结账,按人名来分类的,判断如果选择的消费是属于不同的人,那么不让结账。/// <summary>
            /// 不能选择多个顾客去结账
            /// </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;        }
      

  7.   

    zyl_leilei
    (小蕾)谢谢小蕾   你的方法可用。是我想的太复杂了