CurrentCellChanged中直接将checkBox设置为两种情况,true,false;
一次
dataGrid[当前行,当前列]=bool.Parse("true");
第二次
dataGrid[当前行,当前列]=bool.Parse("false");重复即可。

解决方案 »

  1.   

    DataGridBoolColumn.AllowNull = False
    另外数据源中的数据也应该是没有DBNull值的。
      

  2.   

    我这样写:
    datagrid1.Columns["IsMandatory"].AllowDBNull=false;
    可还是有灰色出现,郁闷
      

  3.   

    CurrentCellChanged中直接写
    if (dataGrid.CurrentCell.ColumnNumber==你的CheckedBox列数)
    {
    string checkBoxValue=dataGrid[dataGrid.CurrentRowIndex,CheckedBox列数].ToString();
    if (checkBoxValue=="")
    checkBoxValue="true";
    bool bcheckBoxValue=bool.Parse(checkBoxValue);
    dataGrid[dataGrid.CurrentRowIndex,CheckedBox列数]=!bCurBoolValue;
    }
      

  4.   

    不好意思,错了,将dataGrid[dataGrid.CurrentRowIndex,CheckedBox列数]=!bCurBoolValue;改成dataGrid[dataGrid.CurrentRowIndex,CheckedBox列数]=!bcheckBoxValue;
      

  5.   

    不会吧,还不能用。你在CurrentCellChanged事件中的程序贴出来了看一下。
      

  6.   

    建列的程序在上面,
    private void dgdFunctionArea_CurrentCellChanged(object sender, System.EventArgs e)
    {
    if (dgdFunctionArea.CurrentCell.ColumnNumber==3)
    {
    string checkBoxValue=dgdFunctionArea[dgdFunctionArea.CurrentRowIndex,3].ToString();
    if (checkBoxValue=="")

    checkBoxValue="true";

    bool bcheckBoxValue=bool.Parse(checkBoxValue);
    dgdFunctionArea[dgdFunctionArea.CurrentRowIndex,3]=bcheckBoxValue;

    } }
      

  7.   

    这个dgdFunctionArea_CurrentCellChanged事件,在鼠标第一次点击cell时触发,
    当鼠标不移动然在cell里点,他就没反应了
      

  8.   

    private void Form1_Load(object sender, System.EventArgs e)
    {
    DataTable dtblFunctionalArea = new DataTable();
    DataColumn dtcCheck = new DataColumn("IsMandatory");
    dtcCheck.DataType = System.Type.GetType("System.Boolean");
    dtcCheck.DefaultValue = true;
    dtblFunctionalArea.Columns.Add(dtcCheck); DataColumn dc = new DataColumn("dd");
    dtblFunctionalArea.Columns.Add(dc);
    for(int i = 1; i< 10;i++)
    {
    DataRow dr = dtblFunctionalArea.NewRow();
    dr[1] = "A"+i.ToString();

    dtblFunctionalArea.Rows.Add(dr);
    }
    dataGrid1.DataSource = dtblFunctionalArea;
    } private void dataGrid1_Click(object sender, System.EventArgs e)
    {
    if (dataGrid1.CurrentCell.ColumnNumber==0)
    {
    string checkBoxValue=dataGrid1[dataGrid1.CurrentRowIndex,0].ToString();
    if (checkBoxValue=="")
    checkBoxValue="true";

    bool bcheckBoxValue=bool.Parse(checkBoxValue);
    dataGrid1[dataGrid1.CurrentRowIndex,0]=!bcheckBoxValue;
    }
    }
    这样子可以的。
      

  9.   

    你的程序中
    dgdFunctionArea[dgdFunctionArea.CurrentRowIndex,3]=bcheckBoxValue;要改成
    dgdFunctionArea[dgdFunctionArea.CurrentRowIndex,3]=!bcheckBoxValue;
      

  10.   

    把你的考过去用,但还是会出现 “灰色选中”...........
    可以把你程序发来吗?  
    [email protected]
      

  11.   

    上面程序确实还会有些问题,下面用MouseUp就不会有问题了。有问题继续探讨。
    private void dataGrid1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    DataGrid.HitTestInfo hti = this.dataGrid1.HitTest(e.X, e.Y);  
    try  
    {  
    if( hti.Type == DataGrid.HitTestType.Cell && hti.Column == 0) 
    {  
    this.dataGrid1[hti.Row, hti.Column] = ! (bool) this.dataGrid1[hti.Row, hti.Column];  
    }  
    }                                                                                                    
    catch(Exception ex)  
    {  
    MessageBox.Show(ex.ToString());  
    }  
    }
    刚才回复不了了,提示不过连续三次以上回贴。
      

  12.   

    确实可以拉,谢谢luminrong(卢民荣)