0
I have a dataGridView and do the check to see if in the column of type Datagridviewcheckboxcolumn there are any selected lines. If there is at least one line with this selected field executing an action type, otherwise it triggers a message of type Messabox.
Int32 verificaCheckBoxGrid = 0;
//varrendo o dataGridView
for (Int32 index = 0; index < meuDataGridView.Rows.Count; index++) {
// verifica se pelo menos 1 checkbox do grid esta ativado
if (bool.Parse(meuDataGridView.Rows[index].Cells[0].FormattedValue.ToString()) == true) {
verificaCheckBoxGrid++;
}
}
// se não conter pelo menos 1 checkbox ativado no dataGridView
if (verificaCheckBoxGrid < 1 || meuDataGridView.Rows.Count == 0) {
MessageBox.Show("Nenhuma Nota Selecionada", "A T E N Ç Ã O", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
I would like to do something that would be with the most presentable code as for example in this case below that is checked if any of the radiobutton’s that are in a groupBox has at least one selected, according to this question.
// usando LINQ - verifica se todos os checkbox dentro do grupo box estão desmarcados
if (!gbTipoDePagamento.Controls.OfType<RadioButton>().Any(x => x.Checked)) {
MessageBox.Show("Selecione Um Tipo De Pagamento", "A T E N Ç Ã O", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
How to know if there is something like:
if (!nomeDoDataGridView.Controls.OfType<DataGridViewCheckBoxColumn>().Any(x => x.Checked))
You are using some Data Model in your Datagrid?
– Marcos Brinner