Mr

0
0

Hi, Please how can i enable filtering/sorting on the datagridview?.

  • You must to post comments
0
0

Hi Francis,

I have put together a small sample, that you can download here: http://wisej.s3.amazonaws.com/support/attachments/DgvSortFilter.zip

dgvsortfilter

The datagridview is populated from a BindingSource created by a DataTable. All columns can be sorted by default by clicking on its column header.
In my sample I want to prevent the ID column from being sorted by the user with the following code:

this.dataGridView1.Columns[“ID”].SortMode = DataGridViewColumnSortMode.NotSortable;

Then I added 2 buttons to show how to sort / filter by code:

this.dataGridView1.Sort(dataGridView1.Columns[“Name”], System.ComponentModel.ListSortDirection.Ascending);

And filter the BindingSource that will automatically update the bound datagridview:

bs.Filter = “Town = ‘New York'”;

Hope that helps.

Best regards
Frank

Attachment
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.