DataGridView save filtering after reload

前端 未结 4 2119
春和景丽
春和景丽 2021-02-10 20:34

I have some problem with DataGridView in C#.

case is:

I do some update on database then I reload DataGridView with new values:

myDataGridView.Dat         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-10 21:10

    Ok, I found the solution, maybe it will help somebody: [btw. I made some language mistake filtering = sorting ;-)]

       DataGridViewColumn oldColumn = dataGridView1.SortedColumn;
    
       ListSortDirection direction;
       if (dataGridView1.SortOrder == SortOrder.Ascending) direction = ListSortDirection.Ascending;
       else direction = ListSortDirection.Descending;
    
       databaseUpdateFunction();
    
       DataGridViewColumn newColumn = dataGridView1.Columns[oldColumn.Name.ToString()];
       dataGridView1.Sort(newColumn,direction);
       newColumn.HeaderCell.SortGlyphDirection =
                        direction == ListSortDirection.Ascending ?
                        SortOrder.Ascending : SortOrder.Descending;
    

    I used parts of code from : link text

提交回复
热议问题