0

DataGridView列を含むを使用していCheckBoxます。その列の値を取得しようとすると、常に false になります。理由を教えてください。

これが私のコードです:

private void dataGridViewCrossRef_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
     {
       bool isChecked1 = false;
       isChecked1 = (Boolean)dataGridViewCrossRef[25, e.RowIndex].FormattedValue;
       if (isChecked1)
       {
          //Some code
       }
     } 
4

2 に答える 2

0

チェックボックスにバインドされたデータは整数であるため、コードを次のように変更すると機能しました。

ありがとう

private void dataGridViewCrossRef_CellContentClick(オブジェクト送信者、DataGridViewCellEventArgs e) { if (e.ColumnIndex == 25) { int CellValue = 0; CellValue = Convert.ToInt16(dataGridViewCrossRef[e.ColumnIndex, e.RowIndex].EditedFormattedValue); if (CellValue == 1) {

            }
        }
    }
于 2013-01-28T08:31:31.793 に答える
0

を試すCellContentClick Event

    private void dataGridViewCrossRef_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
        if (e.ColumnIndex == 25)
        {
            bool IsBool = false;
            if (bool.TryParse(dataGridViewCrossRef[e.ColumnIndex, e.RowIndex].EditedFormattedValue.ToString(), out IsBool))
            {
               //Some code
            }
        }
    }

編集

これを試してみるCellClick Eventと、あなたを宣言する必要がありdataTableますpublic

   private void dataGridViewCrossRef_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        if (e.ColumnIndex == 25)
        {
            //Find primaykey or something unique from your dataTable   
            DataRow[] Rows = dataTable.Select("Id = '" + dataGridViewCrossRef[0, e.RowIndex].EditedFormattedValue.ToString() + "'");

            Rows[0]["NameOfColumnHasCheckBox"] = !bool.Parse(Rows[0]["NameOfColumnHasCheckBox"].ToString());
        }
    }
于 2013-01-28T07:31:44.220 に答える