1
Hello!
When clicking a button, I need you to update the value of a cell in the datagridview
.
follows the code I tried but didn’t work.
private void btnAcesso_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow item in dgvLista.SelectedRows)
{
dgvLista.Rows[item.Index].Cells["acesso"].Value = "S";
}
}
You have to update from the selected line.
Note: Enter the foreach
but does not update.
Thank you.
Grid completion:
var source = new BindingSource();
source.DataSource = lstMenuAux;
dgvLista.DataSource = source;
You used the
datagridview.DataSource
to insert the data into the grid?– Marco Giovanni
Yes, with the help of
DataBinding
– novato
You should change the model you set in the datasource, for example
ItemDataGridView obj = (ItemDataGridView)dgvLista.CurrentRow.DataBoundItem;
obj.acesso = "S";
, recalling that Itemdatagridview is the class you used to set in the datasource– Marco Giovanni
I don’t understand. where you got that one from
ItemDataGridView
does not appear here– novato
Replace Itemdatagridview with the class you used to play in the datasource of datagridview
– Marco Giovanni
Post the code of how you fill in the datagridview
– Marco Giovanni
Okay, posted, edited in question
– novato
What is the type of
lstMenuAux
?– Jéf Bueno
It is an object.. a model.. a list of objects
– novato
Yes, young man, I know that. I want you to type the name of the guy here, so I can write an answer.
– Jéf Bueno
Sorry... List<Menumodel>
– novato
Try to exchange Itemdatagridview for Menumodel
– Marco Giovanni
I tried Marco, but it didn’t work.. It’s in the question update
– novato
Marco. It worked out! Thank you!
– novato