在不移动列表中项目的情况下获取Bindingsource的上一行和下一行信息 [英] Getting Bindingsource previous and next line information without moving the item in the list

查看:51
本文介绍了在不移动列表中项目的情况下获取Bindingsource的上一行和下一行信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在数据库中存储自己的rowindex,以用于跟踪表的顺序.但是,当用户插入新项目时,我不想检索所有现有项目,而是想检索上一条和下一条记录的rowindex并拆分 一半.目前,我的代码看起来像这样,但是通过移至上一个和下一个记录,我得到了一些奇怪的结果.在不实际移至上一行的情况下获取此信息的最佳方法是什么?

I am storing my own rowindex in my database for a table to keep track of the order of items. However, when a user inserts a new item, instead of re-numbering all the existing items, I'd like to retrieve the rowindex of the previous and next records and split it in half. Currently, my code looks like this but I am getting some strange results by moving to the previous and next records. What's the best way to get this information without actually moving to the previous row?

Dim IndexedBindingSource As BindingSource
Dim CurrentRow As Integer
Dim PreviousRow As Integer
Dim NewRow As Integer

CurrentRow = IndexedBindingSource.Current("RowIndex")
IndexedBindingSource.MovePrevious()
PreviousRow = IndexedBindingSource.Current("RowIndex")
IndexedBindingSource.MoveNext()
NewRow = Math.Round(((CurrentRow - PreviousRow) / 2) + PreviousRow)


推荐答案

您得到什么样的奇怪结果?

What kind of strange results are you getting?

如果在索引0处插入新记录会发生什么?

What happens if you insert a new record at index 0?

请记住,应该将排序顺序显式设置为RowIndex字段,否则您不能保证项目的顺序.

Keep in mind that the sort order should be explicitly set to the RowIndex field or you can't guarantee the order of items.

还请记住,绑定到该绑定源的任何控件都将受到位置变化的影响,这又可能导致其他变化,具体取决于您正在处理的事件类型.您可能需要暂停绑定控件上的绑定 更改位置之前.

Also keep in mind that any controls bound to that binding source will be affected by the change in position and that in turn could cause other changes depending on what kind of events you are handling.  You may need to suspend binding on bound controls before changing position.

或者您可能要搜索基础数据表;您可以使用Select方法来获得索引最大但仍小于当前索引的行.这可能确实是最好的选择,而不是依赖于项目中的顺序 表格/视图.

Or you may want to search the underlying data table; you could use the Select method to get the row with the greatest index which is still less than the current index.  This might really be the best bet, rather than relying on the order of items in the table/view.


这篇关于在不移动列表中项目的情况下获取Bindingsource的上一行和下一行信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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