Fórum Verificar checkbox em gridview #506062
02/01/2015
0
1 2 3 4 5 6 7 8 9 10 11 12 13 | private void itemLocacaoDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { foreach (DataGridViewRow dr in itemLocacaoDataGridView.Rows) { if (bool.Parse(dr.Cells[0].EditedFormattedValue.ToString())) { BtnDevolucao.Enabled = true; } else { BtnDevolucao.Enabled = false; } |
ou este, mas o resultado é o mesmo :
1 2 3 4 5 6 7 8 9 10 | for (int i = 0; i < itemLocacaoDataGridView.Rows.Count; i++) { if (bool.Parse(itemLocacaoDataGridView[0, i].EditedFormattedValue.ToString())) { BtnDevolucao.Enabled = true; } else { BtnDevolucao.Enabled = false; } |
[img]http://arquivo.devmedia.com.br/forum/imagem/343353-20150102-194224.png[/img]

Jair Souza
Curtir tópico
+ 0Post mais votado
05/01/2015
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.Columns[e.ColumnIndex].Name.Equals("chk")) { ManipulaBotao(); } } private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.Columns[e.ColumnIndex].Name.Equals("chk")) { ManipulaBotao(); } } private void ManipulaBotao() { button1.Enabled = false; foreach (DataGridViewRow dr in dataGridView1.Rows) { if (bool.Parse(dr.Cells["chk"].EditedFormattedValue.ToString())) { button1.Enabled = true; break; } } } |
Inclui uma chamada ao método CellContentDoubleClick, se isto não for feito não vai funcionar.
Se o grid possuir muitas linhas pode afeta a performance, então deve-ser ficar atento a isto.
Soeuseijothaz

Gostei + 1
Mais Posts
04/01/2015
Soeuseijothaz
1 2 3 4 5 6 7 8 9 10 | foreach (GridViewRow gvItem in SeuGridView.Rows) { CheckBox ck; ck = (CheckBox)gvItem.FindControl("SeuCheck"); if (ck.Checked) { BtnDevolucao.Enabled = true; break; } } |
Gostei + 0
04/01/2015
Jair Souza
[img]http://arquivo.devmedia.com.br/forum/imagem/343353-20150104-165449.png[/img]
Se mudo no foreach para DataGridViewRow dá este outro erro :
[img]http://arquivo.devmedia.com.br/forum/imagem/343353-20150104-165549.png[/img]
Será que está no evento certo ?
Gostei + 0
05/01/2015
Soeuseijothaz
Então favor desconsiderar esta resposta.
Sempre que você abrir um post é bom destacar que esta usando "windows form" ou "web form", assim facilitar a ajuda e fica mais produtivo.
Estou precisando de algo parecido em um windows form que tenho e estou tendo dificuldade e criar esta lógica.
Complica pois tem-se de preocupar com vários métodos: CellContentClick, CellValueChanged ou CellContentDoubleClick.
Se conseguir fazer posto o resultado aqui.
Gostei + 0
05/01/2015
Jair Souza
Valeu, muito obrigado !
Gostei + 0
06/01/2015
Soeuseijothaz
Valeu, muito obrigado !
Sem querer ser chato, mas sendo chato, é prudente implementar usando o CellContentDoubleClick.
Dependendo da velocidade do duplo clique pode ocorrer do controle ficar habilitado sem nenhum check marcado.
O tratamento no método CellContentDoubleClick , para evitar aborrecimentos futuros.
Mas que bom que funcionou.
Gostei + 0
07/01/2015
Jair Souza
Valeu !
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)