I would like to sort my Datagridview at the end of my DownloadFileCompleted event.
I tried the following source which is working if it's called on a buttonClick event, but it's not with my DownloadFileCompleted event and I don't understand why.
// Does work
private void bt_test_1_Click(object sender, EventArgs e)
{
dg_logiciel.Columns[1].SortMode = DataGridViewColumnSortMode.Programmatic;
dg_logiciel.Sort(dg_logiciel.Columns[1], ListSortDirection.Ascending);
}
// Does not work
void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
// mycode
dg_logiciel.Columns[1].SortMode = DataGridViewColumnSortMode.Programmatic;
dg_logiciel.Sort(dg_logiciel.Columns[1], ListSortDirection.Ascending);
}
Can someone explain me that?
DataGridViewis never updatedinvokethe sorting calls as theclient_DownloadFileCompletedis asynchronous and thus not on your UI thread. You may have toInvokea call todg_logicielto refresh theDataGridViewas well.dg_logiciel.Invoke((MethodInvoker) delegate() { dg_logiciel.Sort(...); });