Can't retrieve the value of a DataGridView Checkbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Benysh
    New Member
    • Aug 2008
    • 4

    Can't retrieve the value of a DataGridView Checkbox

    Hi everyone.

    I'm having a really annoying problem I can't solve and couldn't find an answer to anywhere, let's see if you got what it takes.

    I have a dataGridView on a C# Windows Form. Unbound. I fill in rows with a button.

    I have a checkbox column which isn't read-only (unlike the other columns) so the user could check whatever row he wants.

    All I simply want is to know (on CellContentClic k) if the checkbox is checked or not!

    I do this for now:

    Code:
    private void dataGridView1_CellContentClick(object sender,DataGridViewCellEventArgs e)
         {
    MessageBox.Show(dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString());
    }
    It works for every other cell, but when clicking a checkbox, it fails and returns:
    "Object reference not set to an instance of an object."
    Why? Because the .Value = null.

    Please please help!

    Thanks alot in advance,
    Ben.
  • Benysh
    New Member
    • Aug 2008
    • 4

    #2
    OK!

    Just managed pulling it off myself:

    MessageBox.Show (dataGridView1[e.ColumnIndex, e.RowIndex].EditedFormatte dValue.ToString ());

    Probably had something to do with if it's in Edit mode or not

    Thanks alot! This forum is awesome!

    Comment

    • kenobewan
      Recognized Expert Specialist
      • Dec 2006
      • 4871

      #3
      Glad we could be of assistance ;). Well done!

      Comment

      • Benysh
        New Member
        • Aug 2008
        • 4

        #4
        heh

        thanks

        though now I have something I didn't manage ;)

        EditedFormatted Value seems to be readonly

        How do I change the checkbox status? For example, on a button click, check/uncheck a certain checkbox cell

        Well?

        Thanksa

        Comment

        • Benysh
          New Member
          • Aug 2008
          • 4

          #5
          *polite bumb*
          Can anyone help with this?

          Comment

          Working...