0
I’m having some difficulty working with the data grid view selection field, I tried to do it this way:
public void Atualizar()
{
Stock obj = new Stock();
for (int A = 0; A < dgv_Entrada.RowCount; A++)
{
int ID_Cod = Convert.ToInt32(dgv_Entrada[1, A].Value);
obj.id_entrada = ID_Cod;
obj.estado = cb_Estado.Text;
}
obj.Actualizar();
}
When running, when selecting but from a row, it only updates the data of the last selected row.
I’m not getting a check of the selected lines.
How do I do that? You can give a practical example?
– António Mateta
Already made, look at the code I posted, I put the method
obj.Actualizar
within thefor
, that’s all– MurariAlex
By doing so he saves all the lines, even the ones I didn’t select, you see made this way. Tentei fazer uma verificação das linhas que estão a ser selecionado desta forma: int ID_Cod = Convert.ToInt32(dgv_Entrada[1, A].Value);
 Boolean x = Convert.ToBoolean(dgv_Entrada["chk_opcao", dgv_Entrada.CurrentRow.Index].Value.ToString()); if(x==true) { obj.id_input = Id_cod; obj.status = cb_Estate.Text; } Else { } but did not result
– António Mateta
Ready, I put a check to see if the value is selected or not. Take a look, just put the name or Dice of the checkbox column.
– MurariAlex
Now it’s working, thanks for your help. If I want to add an option to select everything with a checkbox apart, will it work if I put the name of datagridview . Selectall ?
– António Mateta
You’re welcome. You can only select everything programmatically. Follow this answer https://stackoverflow.com/questions/13242861/check-all-checkbox-items-on-datagridview
– MurariAlex
I got what I wanted, it’s already working, but thank you for everything!
– António Mateta
Just mark my answer as accepted, please
– MurariAlex
I found but another difficulty, I was able to add a checkbox apart with the option to select everything and it works normally, it happens that when I select for example two lunhas and click on select everything, it disables the two previously selected fields and enables the other fields that were not selected, there is the code: foreach (Datagridviewrow Row in dgv_Entrada.Rows) { Datagridviewcheckbcell chk = (Datagridviewcheckboxcell)Row. Cells[0]; chk.Value = ! (chk.Value == null ? false : (bool)chk.Value); }
– António Mateta