How a CheckBox can receive a DataGridView CheckBoxCell

0

In my DataGridView, the user's information is included in the database, whether the user is an administrator or not, this cell has a DataGridViewCheckBoxCell.

Iwanttopassthevalue(True/False)toaCheckBoxControl.Itriedusingthefollowingcode,butitdoesnotwork.

Debugging,InoticedthatthevariableadmalwaysisTrue,eventhoughitcomesfromtheBankandtheCheckBoxevenreceivingthevalue,itisnotmarked,nothinghappens.

TheCheckBoxisbydefaultwithCheckStateIndeterminate

privatevoidtsbEditarUsuario_Click(objectsender,EventArgse){if(gridConsultaUsuario.SelectedRows.Count>0){ucEditarUsuarioeditarUsuario=newucEditarUsuario();editarUsuario.txtNome_detalhe.Text=gridConsultaUsuario.CurrentRow.Cells[0].Value.ToString();editarUsuario.txtUserCadastro_detalhe.Text=gridConsultaUsuario.CurrentRow.Cells[1].Value.ToString();editarUsuario.txtEmail_detalhe.Text=gridConsultaUsuario.CurrentRow.Cells[2].Value.ToString();editarUsuario.cboSetor_detalhe.SelectedItem=gridConsultaUsuario.CurrentRow.Cells[3].Value.ToString();editarUsuario.cboCargo_detalhe.SelectedItem=gridConsultaUsuario.CurrentRow.Cells[4].Value.ToString();varadm=(DataGridViewCheckBoxCell)this.gridConsultaUsuario.CurrentRow.Cells[5];editarUsuario.chkAdm_consulta.Checked=adm.Selected;_tabSystem.subTab(telaPrincipal.tabPrincipal.SelectedIndex,editarUsuario);}else{MessageBox.Show("Selecione um usuário");
            }
        }
    
asked by anonymous 15.01.2016 / 15:20

2 answers

0

After a little research I was able to solve the problem.

editarUsuario.chkAdm_consulta.Checked = Convert.ToBoolean(gridConsultaUsuario.CurrentRow.Cells[5].Value.ToString().ToLower());
    
18.01.2016 / 13:42
1

Try :

int index = gridConsultaUsuario.SelectedRows[0].Index;
ckAdm.Checked= Convert.ToBoolean(gridConsultaUsuario.Rows[index].Cells[5].Value);
    
17.01.2016 / 19:01