How to update one Datagridview when changing the other?

Asked

Viewed 34 times

0

I have a DataGridView called gridProfissional which lists all the professionals I have registered in a table.

I have another DataGridView called gridAgenda that lists the days that the professional attends.

I have a function that works correctly:

private void preencheGridAgenda()
{
    List<datum> listaData = new List<datum>();
    int idAgenda = Convert.ToInt32(gridProfissional.CurrentRow.Cells[0].Value.ToString());
    listaData = modelOff.data.Where(p => p.idAgenda.Equals(idAgenda)).ToList();
    gridData.DataSource = listaData;
    gridData.Select();
}

My intention is this: when selecting a line on gridProfissional, call the function preencherGridAgenda and update gridAgenda.

At the event Scroll of gridProfissional I’m calling the function preencherGridAgenda, however, I select any line from my gridProfissional and the function is not called.

I’m using the wrong event (Scroll)? There’s another event for that?

1 answer

1


The best way to do this is by using the event SelectionChanged of DataGridView

Browser other questions tagged

You are not signed in. Login or sign up in order to post.