-2

In my window form application I have a datagridview which has a checkbox column I want to retrieve its value is checked or not I attempted

    if ((bool)dataGridView1[columnindex,rowindex].Value ==true )
{
   MessageBox.show ("checked");
 }

but it doesn't work please answer me

3 Answers3

0

This should works fine:

var value = dataGridView1[columnindex, rowindex].Value

So if you said "it doesn't work" - than just you need to provide us more information about error you got, etc.

XardasLord
  • 1,764
  • 2
  • 20
  • 45
0

You can try following code snippet

foreach (DataGridViewRow roow in dataGridView1.Rows)
{
   DataGridViewCheckBoxCell chkchecking = roow.Cells[0] as DataGridViewCheckBoxCell;

    if (Convert.ToBoolean(chkchecking.Value) == true)
    {
    }
}
santosh singh
  • 27,666
  • 26
  • 83
  • 129
0
DataGridViewCheckBoxCell checkbox = (DataGridViewCheckBoxCell)dataGridView1.CurrentCell;
bool ischecked = (bool)checkbox.EditedFormattedValue;
if (ischecked == true)
{
MessageBox.Show("True")
}

this code can get datagridview checkbox cell value