如何对GridView的选定行进行排序? [英] How to sort the selected rows of a gridview?

查看:96
本文介绍了如何对GridView的选定行进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到处都在寻找它,但是只找到了对整行进行排序的方法.也许我输入的搜索词有误.

我正在编写一个从记忆棒上的数据库读取的项目,可以对其进行排序,然后将其写回.
我想要做的是突出显示几行,然后仅对选定的行进行排序.我有一个下拉列表,用于选择排序依据"列和一个排序按钮.

我确定一定有这样的示例,因此欢迎使用任何指针.

Hi, I have looked everywhere for this but have only found the method to sort whole rows. Maybe I''m wording my search incorrectly.

I am writing a project that reads from a db on a memory stick, allows sorting and then writed it back.
What I want to do is Highlight a few rows, then sort just the selected rows. I have a drop down list to select the ''sort by'' column and a sort button.

I''m sure there must be examples of this out there somewhere so any pointers welcome.

推荐答案

我不,您不会在以下位置找到示例这个.网格被写入(合理地如此)以处理它所显示的整个记录​​集.排序全部或不排序.

你不是那样做的.您对待手工艺品的记录块的处理方式与其余方式不同.您将如何处理未连接(不相邻)记录的排序?一旦排序",它们如何最终回到列表中?他们被转移到一个连续的街区了吗?是这样,在哪里?为了腾出空间而需要移动的记录会发生什么?排序后的记录是否返回到原来选择的插槽"中? ...

从表面上看,这听起来很容易,但是您需要考虑很多因素.我怀疑您是否会在任何地方使用DataGridView或DataGrid在Web上找到单个示例.

您必须获取选定的记录,使用Sort方法将它们放入自己的集合中,然后从原始数据表中删除记录,根据业务规则将排序后的记录放回去,然后将网格重新绑定到新的安排.

顺便说一句,数据库不在乎记录顺序,也不支持以特定顺序将记录放回数据库中.排序顺序由ORDER BY子句或select处理.物理表本身没有记录顺序之类的东西.这意味着您必须在表中有一列专门用于维护排序顺序.
I don''t you''re going to find examples on this. The grids are written (justifiably so) to treat the entire set of records it is showing the same. You sort all or nothing.

You''re not doing that. You''re treating an artibtrary block of records differently than the rest. How are you going to handle sorting disconnected (non-adjacent) records? Once "sorted", how do they end up back in the list? Are they moved into a contiguous block? Is so, where? What happens to the records that have to move to make room? Do the sorted records go back into the original selected "slots" that were selected? ...

This sounds easy on the surface, but there''s a lot you have to account for. I doubt you''re going to find a single example of this on the web anywhere, using a DataGridView or DataGrid anyway.

You''d have to grab the records that are selected, put them into their own collection with a Sort method, then remove the records from the original datatable, put the sorted ones back in according to your business rules, then rebind the grid to the new arrangement.

BTW, databases do not care about record order and do not support putting the records back into the database in a specific order. Sort order is handled by the ORDER BY clause or a select. There is no such thing as record order in the physical table itself. This means you''d have to have a column in the table dedicated to maintaining sort order.


这篇关于如何对GridView的选定行进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆