0
In my Datagridview brings from the Database the user information, among them if he is administrator or not, this cell has a Datagridviewcheckboxcell.
I want to pass its value (True/False) to a Checkbox Control. I tried using the following code, but it doesn’t work.
Debugging, I realized that the variable Adm is always True, even if it comes False from the Bank and the Checkbox even receiving the value, it is not marked, nothing happens.
Checkbox is by default with Checkstate Indeterminate
private void tsbEditarUsuario_Click(object sender, EventArgs e)
{
if (gridConsultaUsuario.SelectedRows.Count > 0)
{
ucEditarUsuario editarUsuario = new ucEditarUsuario();
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();
var adm = (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");
}
}
Gabriel, for the record, you don’t need to tag
visual-studio
when the problem is not explicitly with the IDE. If interested, read What is a programming language, IDE and compiler?– Jéf Bueno
Only with this piece of code it is difficult to know where the error is.
– Marco Souza
But what else is needed? I can post the entire method but I don’t know if it makes a difference.
– Gabriel Bernardone