问题
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