Hi All

I am developing a Windows Application for Library Management System.

In my DataBase I have a column named IssueStatus the datatype of this column is bit and by default it adds the value as 0.

When I bind the DataGridView Control to this table. The Column named IssueStatus displays a CheckBoxes for each row.

Now I want to validate whether any of the checkbox is checked or not.

I have used the following code to do this task but it is generating the following error:

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    if (e.ColumnIndex == 5)
    { 
        if((dataGridView1.CurrentRow.Cells["DataGridViewCheckBoxCell"]).CheckState ==CheckState.Checked)
        {             
            MessageBox.Show("Checked");
        }
    }
}

Please note that the column IssueStatus is 6th Column in the database.

I am getting the following error message:

'System.Windows.Forms.DataGridViewCell' does not contain a definition for 'CheckState' and no extension method 'CheckState' accepting a first argument of type 'System.Windows.Forms.DataGridViewCell' could be found (are you missing a using directive or an assembly reference?)

I just want to check whether the checkbox is checked or not.

Can anyone help me out in identifying the error?

Please help me out in finding out the error.

Thanks in advance!!

S2009, It's prefable to use dataGridView1_CellValueChanged instead of dataGridView1_CellContentClick, the code will be:

private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
    {
        if (e.ColumnIndex == 5)
            if ((bool)dataGridView1.CurrentCell.Value == true)
                MessageBox.Show("Checked");
    }

S2009, It's prefable to use dataGridView1_CellValueChanged instead of dataGridView1_CellContentClick, the code will be:

private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
    {
        if (e.ColumnIndex == 5)
            if ((bool)dataGridView1.CurrentCell.Value == true)
                MessageBox.Show("Checked");
    }

end quote.

Hi

Thanks for your Reply.

I have tried the coding as given by you. But the message box is displayed only if I check mark all the rows in the datagridview.

But I want to display the message box when atleast one of them is selected and not when all the rows are selected.

Can you help me out in doing out this desired task?

Please somebody help me out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.