本文介绍了DataGridView重新加载后保存过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



案例是:



我对C#中的DataGridView有一些问题数据库,然后我用新的值重新加载DataGridView:

  myDataGridView.DataSource = myDataSet.Tables [0] 


做这个过滤案例的方法是什么?



感谢任何想法。

解决方案

好的,我找到了解决方案,也许会帮助某人:
[btw。我做了一些语言错误过滤=排序; - )]

  DataGridViewColumn oldColumn = dataGridView1.SortedColumn; 

ListSortDirection方向;
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 have some problem with DataGridView in C#.

case is:

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

myDataGridView.DataSource = myDataSet.Tables[0]

Everything is ok, but recently I was asked if there is possibility to keep the same column filtering applied after reloading data?

What would be approach to do this filtering case?

Thanks for any ideas.

解决方案

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

这篇关于DataGridView重新加载后保存过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 22:20