如何过滤DataGridView的结果? (VB) [英] How to filter DataGridView results on the fly? (VB)

查看:146
本文介绍了如何过滤DataGridView的结果? (VB)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataGridView显示存储在数据库中的信息。说我有一个专栏(数学,英语和科学),我如何做到这一点,所以DataGridView只会显示我选择的主题(最好是通过一个下拉菜单框)。所以如果我在下拉框中选择了英文,它只会显示具有Subject = English的数据条目。



我很无能为力,所以帮助非常感谢,谢谢。
(这是在VB中)

解决方案

您可以对dataview进行过滤,并在datagrid上显示。 p>

  Dim view as new DataView //'声明一个新的dataview 
view.Table = someDataSet.Tables(Sometable) //'你正在使用的表
view.RowFilter =subject ='English'//'你正在编写一个where子句的过滤器
someDatagridview.DataSource = view //'bind它到DGW


I have a DataGridView showing information stored in a database.

Say I have a Column for subjects (Maths, English and Science), how can I make it so the DataGridView will only show the subject I choose (preferably via a dropdown box). So if I have English selected in the dropdown box, it will only show the data entries that have Subject = English.

I'm pretty clueless so help is greatly appreciated, thanks. (This is in VB)

解决方案

You can filter on your dataview and showing that on the datagrid.

Dim view as new DataView //'Declare a new dataview
view.Table = someDataSet.Tables("Sometable") //'the table you're working with
view.RowFilter = "subject = 'English'" //'The filter as you were writing a where clause
someDatagridview.DataSource = view //'bind it to DGW

这篇关于如何过滤DataGridView的结果? (VB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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