winForm 下的dataGrid中复选框,为什么得点两下鼠标才能选中?
点第一次为选中单元格,点第二次才能打上钩或去掉钩。
有没有办法能点一次就能行?

解决方案 »

  1.   

    写代码在相应的嵌入的checkbox的mousedown,记录鼠标点击次数,然后改变相应的值。
      

  2.   

    try
    http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
      

  3.   

    都是高人回答的
    我就不说话了.
    应该重载mouserdown事件。
    一次完成两件事。
      

  4.   

    除非你只要点复选框,否则当你重载了Mousedown后,要想做其它事就麻烦了
    所以点两次又何妨?
      

  5.   


    源码下载:在DataGridColumnStyle的单元格中使用DateTimePicker、ComboBox、NumericUpDown等控件
    http://community.csdn.net/Expert/topic/3522/3522038.xml?temp=.2270777
      

  6.   

    /// <summary>
    /// 对DataGrid中的CheckBox进行值判断,并对数据库做出修改
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void dataSource_CurrentCellChanged(object sender, System.EventArgs e)
    {
    try
    {
    string temp = dataGridView[Convert.ToInt32(dataGridView.CurrentCell.RowNumber),0].ToString();
    this.dataGridView.Select(dataGridView.CurrentCell.RowNumber);
    DataAccess data = new DataAccess();
    //判断是否点中的是CheckBox列,以保证其值正确更改
    if(dataGridView.CurrentCell.ColumnNumber == 12)
    {
    //判断CheckBox单元格的值,并根据其值更新数据库
    if(dataGridView[Convert.ToInt32(dataGridView.CurrentCell.RowNumber),12].ToString() == "False")
    {
    dataGridView[Convert.ToInt32(dataGridView.CurrentCell.RowNumber),12] = true;
    string query_sql = "update accounttype set accflag = '1' where id = '" + temp + "'";
    data.ExecuteSQL(query_sql);
    }
    else if(dataGridView[Convert.ToInt32(dataGridView.CurrentCell.RowNumber),12].ToString() == "True")
    {
    dataGridView[Convert.ToInt32(dataGridView.CurrentCell.RowNumber),12] = false;
    string query_sql = "update accounttype set accflag = '0' where id = '" + temp + "'";
    data.ExecuteSQL(query_sql);
    }
    }
    else
    {
    //选中的不是CheckBox列就跳出此过程
    return;
    }
    }
    catch
    {
    MessageBox.Show("表格中未有任何记录!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
    } }