DataGridView Checkbox value

I have a winForm application that contains a DataGridView.  The grid contains several columns, one of which is a checkbox column.  I'm able to target the column but the boolean value is always true no matter the actual state on screen.  Why does the checkbox show "true" when it's clearly unchecked?  This same type of code works fine for the other text cells.
private void UpdateAdminMemberRecord(DataGridViewCellEventArgs e)
        {
            //Instantiate objects  
            String strNewValue = "";
            String strColumnName = "";
            Int32 intTeamMemberID = 0;
            Boolean blnIsActive = false;
            OleDbCommand cmdUpdateMembers = new OleDbCommand();
            Tools objTools = new Tools();

            switch (grdAdminMembers.Columns[e.ColumnIndex].HeaderText)
            {
                case "FirstName":
                    strNewValue = (String)grdAdminMembers.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
                    break;
                case "LastName":
                    strNewValue = (String)grdAdminMembers.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
                    break;
                case "Username":
                    strNewValue = (String)grdAdminMembers.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
                    break;
                case "Password":
                    strNewValue = (String)grdAdminMembers.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
                    break;
                case "IsActive":
                    blnIsActive = (Boolean)grdAdminMembers.Rows[e.RowIndex].Cells["IsActive"].Value;
                    if (blnIsActive == true) { strNewValue = "1"; }
                    else { strNewValue = "0"; }
                    break;
            }

Open in new window

Phil5780Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

khan_webguruCommented:
foreach (DataGridViewRow row in dataGridView1.Rows)
    {
        row.Cells[CheckBoxColumn1.Name].Value = true;
    }

Open in new window


The Click event might look something like this:

 
private void button1_Click(object sender, EventArgs e)
    {
        List<DataGridViewRow> rows_with_checked_column = new List<DataGridViewRow>();
        foreach (DataGridViewRow row in dataGridView1.Rows)
        {
            if (Convert.ToBoolean(row.Cells[CheckBoxColumn1.Name].Value) == true)
            {
                rows_with_checked_column.Add(row);
            }
        }
        // Do what you want with the check rows
    }

Open in new window


reference: http://stackoverflow.com/questions/1237829/datagridview-checkbox-column-value-and-functionality
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
khan_webguruCommented:
Another concept but source in VB.net hope you will get some IDEA

 
dim chkstr as string
chk1 = CType(myDataGridItem1.FindControl("lnk_field1"), Checkbox). Checked

if chk1.checked = True then
chkstr = "Yes"
else
chkstr = "No"
end if

Open in new window


Reference: http://forums.devx.com/showthread.php?t=163391
0
khan_webguruCommented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.