我无法理解如何允许在运行时填充的DataGridView通过BindingSource排序(当用户单击列标题时)来自XML查询的LINQ是DataSource.
Dim QueryReOrder = From Q In Query _ Where ((0 - Q.Qualifier) / cmbTSStakeValue.Text) <= 0.1 _ Order By Q.Qualifier Descending _ Select Q Dim bs As New BindingSource bs.DataSource = QueryReOrder DGFindMatch.DataSource = bs
一些DataGridView的属性是:
Sort Nothing String SortProperty Nothing System.ComponentModel.PropertyDescriptor SupportsAdvancedSorting False Boolean SupportsChangeNotification True Boolean SupportsFiltering False Boolean SupportsSearching False Boolean SupportsSorting False Boolean
是否有一个简单的解决方案,允许用户通过单击列标题对这些值进行排序?
谢谢!
您需要将LINQ查询的结果转换为支持排序功能的内容.这通常通过从BindingList派生类并在派生类中实现Sorting Core功能来完成.
有很多实现可供选择的例子,这是一个非常直接的实现.这是在MSDN上执行此操作的示例.
一旦实现了这一点,您只需将结果放入其中并将其用作DataSource,Grid应允许用户使用列进行排序.
//I know that you asked the question in VB.NET but I don't know the syntax that well. public class SortableBindingList: BindingList { //override necessary sort core methods } SortableBindingList list = new SortableBindingList (QueryReOrder.ToList()); //use list as your DataSource now