我们如何使用 BindingSource.Filter 属性从行数 30 到 50 中获取行

发布于 2024-10-09 20:02:16 字数 354 浏览 0 评论 0原文

我正在使用 C#、数据表和绑定源控件。 如果数据集中有一个名为 Recordsn 的列名称,那么我们可以如下所示进行过滤。

bindingSource1.Filter = "Recordsn >= 30 and Recordsn <= 50" ;

但是,在某些情况下,我没有 Recordsn 列。由于 Recordsn 只是行数,我相信我们可以进行过滤,而不必在数据集中插入 Recordsn 列,并且仍然能够过滤行以从中获取行某些起始行到结束行。 有办法吗? 谢谢。 如果在绑定源上不可能,有没有办法在数据表上执行此操作 注意:我使用 30 和 50 只是为了让问题更简单,它可以是任何范围。

I am using c#, datatable and bindingsource control.
If we have a column name called as Recordsn in the dataset then We can filter as shown below.

bindingSource1.Filter = "Recordsn >= 30 and Recordsn <= 50" ;

However,In some cases I donot have the Recordsn column .Since Recordsn is just the row count , I believe that we can do the filter without having to insert the Recordsn column in the dataset and still be able to filter the rows to get rows from certain starting row to ending row.
Is there a way ?
Thanks.
Is there a way to do this on datatable if not possible on bindingsource
Note : I have used 30 and 50 to just make the question simpler , it could be any range.

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

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

发布评论

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

评论(1

栖迟 2024-10-16 20:02:16

设置 BindingSource.Filter 属性只是将该过滤器字符串值传递到 IBindingListView,即附加到 BindingSource 的源。 Filter 字符串的格式取决于实现IBindingListView 的对象。

当您使用DataSet作为源时,这意味着您实际上正在绑定DataView,该DataView附加到DataTable中的 >数据集。查看 MSDN 的 DataView .RowFilter 属性似乎无法根据行计数进行过滤。

简而言之,答案是否定的,你不能按照你的需要去做。为了解决这个问题,您可以创建自己的过滤类,该类位于 DataView 和 DataTable 之间,并限制它公开的行。

Setting the BindingSource.Filter property simply has that filter string value passed onto the IBindingListView that is the source attached to the BindingSource. The format of the Filter string is dependant on the object that implements the IBindingListView.

As you are using a DataSet as the source it means you are actually binding against a DataView that is attached to a specific DataTable from the DataSet. Looking at MSDN for the DataView.RowFilter property there seems no ability to filter against the row count.

So in short, the answer is no, you cannot do as you need. To get around this you could creaet your own filtering class that sits between the DataView and the DataTable and restricts the rows it exposes.

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