对集合进行永久排序
我有一个可观察的集合,它通过 collectionviewsource 向用户公开。集合中项目的属性之一是排序顺序。我试图允许用户永久使用此集合并将更改传播到数据库。
我有 CVS 工作,我可以在其中显示列表框中显示的各个项目。然而现在我必须更改 item.sortorder==cvs.currentindex 并且我无法找出执行此操作的正确方法。
编辑
显然我还不够清楚。 Sortorder 是我的数据库中的一个字段,它是我的对象的一部分,允许用户控制列表控件中显示的项目的位置。我试图让我的用户能够通过将 sortorder 字段的值更改为等于显示项目的当前索引来更改这些项目将来的排序方式。
items 当前的 sortorder 值为 3。
用户将显示的 listitem 移动到位置 0(即第一个位置)
items 新的 sortorder=0 原始 sortorder 的 item 将变为 1 等等,
这可以通过循环排序的 CVS 并使 Item.SortOrder= CVS 来实现。项目索引
I have an observable collection that is exposed to the user by a collectionviewsource. One of the properties on the items in the collection is sortorder. I am trying to allow the user to permanently resort this collection and propagate the changes to the db.
I have the CVS working where I can resort the individual items as they are displayed in the listbox. Now however I have to change the item.sortorder==cvs.currentindex and i am having trouble figuring out the proper way to do this.
EDIT
evidently I was not clear enough. Sortorder is a field in my DB that is part of my object that allows the user to control position of the items as displayed in list controls. I am trying to give my user the ability to change how these items are sorted in the future by changing the value of the sortorder field to equal the current index of the displayed item.
items current sortorder value is 3.
user moves displayed listitem to position 0(ie first position)
items new sortorder=0 item with original sortorder will become 1 etc
this would be achieved by looping through the sorted CVS and making Item.SortOrder= CVS.Item.index
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
数据库通常根据添加到表中的顺序从表中返回行,除非您在查询中指定 order by 子句。更改数据库中的顺序不是一个好主意。相反,尝试使用参数化查询并传入您希望排序的列和方向(从用户首选项中检索)。
Databases return rows from table based typically on the order they were added to the table unless you specify an order by clause in your query. changing the order in the database is not a good idea. instead, try something such as using a parameterized query and passing in the column and direction you wish to be sorted which is retrieved from a user preference.
我想通了。
我回去查看了用来更改元素位置的代码,实际上我正在使用集合本身:
所以我只是这样做了:
我不知道这是否适用于所有情况,但它确实做了我想要的事情想要这个。
I figured it out.
I went back and looked at the code that I was using to change the position of the elements and I am actually using the collection itself:
So I simply did this:
I dont know if this will work in every circumstance but it certainly did what I wanted for this one.