search in datagridview C# winfom

后端 未结 3 1595
小蘑菇
小蘑菇 2021-01-06 11:34

I want to put a search option in DataGridView, i.e., User types the string or int in TextBox and similar records the DataGridView shou

3条回答
  •  攒了一身酷
    2021-01-06 12:18

    If your DataGridView is bound to a DataTable or a DataView, you can do this:

    Create a BindingSource and make BindingSource.DataSource the Datatable or DataView that your DGV is currently using. Then set your DataGridView.DataSource to the BindingSource. Then you can use the BindingSource.Filter property to query your datasource by setting the BindingSource.Filterto your query string which will automatically filter the DGV. You can find the syntax here - it is very similar to basic SQL queries, except you can only use wild cards on the beginning and end of the string.

提交回复
热议问题