Link to home
Start Free TrialLog in
Avatar of Phil5780
Phil5780

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of khan_webguru
khan_webguru
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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