Reputation: 662
I'm showing database records through a DataGridView in a WinForms application. Also , i have a textview , a combobox and a datetimepicker. How can i sort the datagridview to show only records which equals the textview or the combobox or datetimepicker?
Upvotes: 2
Views: 1921
Reputation: 60466
You need the BindingSource
between your, for example, DataSet
and your DataGridView
.
With a BindingSource you are able to filter your DataSource because the BindingSource has a .Filter
property.
If you change the filter, it will filter your DataGridView
too.
BindingSource.Filter Gets or sets the expression used to filter which rows are viewed.
BindingSource myBindingSource = new BindingSource();
myBindingSource.DataSource = myDataTable;
myDataGridView.DataSource = myBindingSource;
myBindingSource.Filter =// your filter
Upvotes: 2