Devexpress - How do I base a Gridcontrol's data on the sorted/filtered data from another GridControl?

对着背影说爱祢 提交于 2019-12-11 12:10:59

问题


I have two GridControls on my form. One is a fairly large dataset, including a column named Score. I want my other GridControl to show a subset of this (e.g. Top 3 and Bottom 3 based on the values of Score).

How can I best accomplish this? If it were the same GridControl I imagine I could just use a different view, but since it's completely separate, should I just grab a copy of the view, filter/sort the data and display it as a new dataset? Or is there a way to link my second GridControl's data to my first's?

edit: I could do grid2.datasource = grid1.datasource and go from there. There won't be any dynamic updates to the table so maybe this is the way to go?


回答1:


I would use the following approach:

1) create a new DataView, filter it based on your approach and set the second gridControl's DataSource to this DataView;

OR

2) set the DataSource property of the second GridControl to the same value and filter the corresponding GridView.




回答2:


No need to create a new DataView. Check out the gridview's CustomRowFilter event.

Use e.ListSourceRow to get the row in the datatable.

So if suppose you want rows with value > 25 to be displayed and the rest hidden

gridView_CustomRowFilter(object sender, RowFilterEventArgs e)
{
      if(dataset.datatable[e.ListSourceRow]["ColumnName"] < 25)
      {  
          e.visible = false;
          e.handled = true;
      }
}


来源:https://stackoverflow.com/questions/6369852/devexpress-how-do-i-base-a-gridcontrols-data-on-the-sorted-filtered-data-from

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!