在 gridview/bindingsource 中重新排序记录

发布于 2024-08-10 06:25:28 字数 447 浏览 7 评论 0原文

我正在使用 Telerik 的 WinForms 控件,并有一个 radGridView,它绑定到绑定源来显示我的数据。我想稍微扩展一下它的功能,为用户提供一种额外的方式来订购记录。

我在网格视图中添加了两个命令按钮(向上、向下)以帮助实现此功能。基本上,当单击“向上”按钮时,我希望当前行与上面的行交换位置;如果单击“向下”按钮,当前行应与下面的行交换位置。

示例数据:

1
2
3
4
5

如果单击第三行的“向上”按钮,数据应如下所示:

1
3
2
4
5

如果单击第三行的“向下”按钮,数据应如下所示:

1
2
4
3
5

我怎样才能实现这一目标?我是否必须修改这些行的绑定源位置或 gridview 行的索引?另一种方式?任何例子都非常感激!

I am using Telerik's WinForms controls and have a radGridView which is bound to a bindingsource to display my data. I would like to expand on the functionality of this a bit to give users an extra way to order the records.

I have added two command buttons to the gridview (Up, Down) to help facilitate this functionality. Basically, when the "Up" button is clicked, I would like the current row to switch places with the row above; if the "Down" button is clicked, the current row should switch places with the row below.

Example data:

1
2
3
4
5

If the "Up" button is clicked on the third row, the data should then look like so:

1
3
2
4
5

If the "Down" button is clicked on the third row, the data should look like this:

1
2
4
3
5

How can I achieve this? Do I have to modifiy the bindingsource positions of these rows, or the gridview row's index? Another way? Any examples are greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兔小萌 2024-08-17 06:25:28

决定使用拖放而不是向上/向下按钮。一切都很好。

Decided to use drag and drop instead of up/down buttons. All is well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文