How to filter DataGridView results on the fly? (VB)

半腔热情 提交于 2019-12-25 18:47:07

问题


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)


回答1:


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


来源:https://stackoverflow.com/questions/15348224/how-to-filter-datagridview-results-on-the-fly-vb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!