DataGridView,BindingSource和vb.net中的排序

时间:2022-11-17 13:59:54

I am emulating the functionality of an old app in VB.Net. I have a DataGridView on my form which is bound to a BindingSource. I have a button on the toolbar which lanuches a sort dialog. The sort dialog allows sorting by up to 3 columns.

我在VB.Net中模拟旧应用程序的功能。我的表单上有一个DataGridView绑定到BindingSource。我在工具栏上有一个按钮,用于指示排序对话框。排序对话框允许最多排序3列。

So I'm building a string from the results of the dialog and setting the BindingSource.Sort property with it. But this doesn't update my DataGridView. Am I missing a step - do I need to tell something to refresh?

所以我从对话框的结果中构建一个字符串,并用它设置BindingSource.Sort属性。但这不会更新我的DataGridView。我错过了一步 - 我需要告诉一些事情要刷新吗?

3 个解决方案

#1


I just tried this with a simple test app, and it sorted without having to call any refresh. Can you post some code? Are you sure you're building up the Sort string correctly?

我只是尝试使用一个简单的测试应用程序,它排序后无需调用任何刷新。你能发一些代码吗?您确定要正确构建排序字符串吗?

#2


Do you have to call the DataGridView.DataBind() method?

你必须调用DataGridView.DataBind()方法吗?

I'm so used to ASP.NET that I forget the WinForms stuff.

我已经习惯了ASP.NET,忘记了WinForms的东西。

#3


What is the underlying object, and does it support sorting? You can check via the .SupportsSorting property (iirc). If it is a DataTable then you should be ok.

什么是底层对象,它是否支持排序?您可以通过.SupportsSorting属性(iirc)进行检查。如果是DataTable那么你应该没问题。

Have you tried applying the sort directly to the Grid?

您是否尝试将排序直接应用于网格?

You can try calling BindingSource.ResetBindings(false) after you update the sort property, just to be safe, but you shouldn't have to.

更新排序属性后,您可以尝试调用BindingSource.ResetBindings(false),只是为了安全起见,但您不应该这样做。

#1


I just tried this with a simple test app, and it sorted without having to call any refresh. Can you post some code? Are you sure you're building up the Sort string correctly?

我只是尝试使用一个简单的测试应用程序,它排序后无需调用任何刷新。你能发一些代码吗?您确定要正确构建排序字符串吗?

#2


Do you have to call the DataGridView.DataBind() method?

你必须调用DataGridView.DataBind()方法吗?

I'm so used to ASP.NET that I forget the WinForms stuff.

我已经习惯了ASP.NET,忘记了WinForms的东西。

#3


What is the underlying object, and does it support sorting? You can check via the .SupportsSorting property (iirc). If it is a DataTable then you should be ok.

什么是底层对象,它是否支持排序?您可以通过.SupportsSorting属性(iirc)进行检查。如果是DataTable那么你应该没问题。

Have you tried applying the sort directly to the Grid?

您是否尝试将排序直接应用于网格?

You can try calling BindingSource.ResetBindings(false) after you update the sort property, just to be safe, but you shouldn't have to.

更新排序属性后,您可以尝试调用BindingSource.ResetBindings(false),只是为了安全起见,但您不应该这样做。