none
CheckBox field in DataGridView cell is not working

    Question

  • Hi all,

    I have created a DataGridView and set the first column to a CheckBox Column. I am adding rows programmatically to the grid. I use the following code to create a new CheckBoxCell :-
                   
                    DataGridViewCheckBoxCell selectionCell = new DataGridViewCheckBoxCell();
                    selectionCell.TrueValue = true;
                    selectionCell.FalseValue = false;
                    selectionCell.Value = false;


    But when the grid comes up and I click on the checkbox, it does not get checked. Doesn't it behave like a normal check box? Do I need to do something else to make it work?

    Thanks in advance.
    Prashant.
    Wednesday, January 14, 2009 11:47 AM

Answers

All replies

  •  You should not ____ a checkbox cell again , Try this code

    DataGridViewCheckBoxCell selectionCell = new DataGridViewCheckBoxCell();

    //selectionCell.TrueValue = true;

    //selectionCell.FalseValue = false;

    //selectionCell.Value = false;

    dataGridView1.Rows.Add();

    // Modify the value in the first cell of the second row.

    this.dataGridView1.Rows[1].Cells[0].Value = "true";

    --- Please mark an aswer if it solves the issue

    Wednesday, January 14, 2009 12:11 PM
  • Hi Akshay,

    Thank you for your reply. But I think you didn't get my question. Let me elaborate a bit.

    Normally when you add a checkbox to a winform, you need not set the checked and unchecked states programmatically, i.e. it automatically checks if it is unchecked and gets unchecked if it is checked. But this is not the case with the DataGridViewCheckBoxCell. I expected it to behave the same way. But when my form comes up with the checkboxes displayed and I try checking one of them, it does not get checked.

    I assume, there is no inherent support for that and I need to handle the click events of the cell to manually set the checked and unchecked states. Please correct me if I am wrong.

    Thanks and regards,
    Prashant.
    Wednesday, January 14, 2009 12:31 PM
  • Normally this is not required , may be if you post your code in detail , it would help!
    Wednesday, January 14, 2009 12:55 PM
  • Hi Akshay,

    Thanks for your help. I got the problem. When you said that it is normally not required, I understood that I have done some mistake while creating the grid. I found that while creating the grid view, I had set the Enable Editing to false. This was causing a problem. Anyways now it works.

    Thanks for your support again.

    Prashant.
    Wednesday, January 14, 2009 1:12 PM