Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGridView Sort

Status
Not open for further replies.

litton1

Technical User
Apr 21, 2005
584
GB
I am having problems while sorting a DGV. At the moment the glyph (triangle) shows but is not enabled to allow a sort on the column. It looks like the header is not enabled? Could this be because the data is bound to a generic list? The properties that I have set are (otherwise assume default). Any help appreciated

Code:
dgv.ReadOnly = false;
dgv.RowHeadersVisible = false;
dgv.Columns["SortColID"].SortMode = DataGridViewColumnSortMode.Automatic;
dgv.Sort(dgv.Columns["SortColID"], ListSortDirection.Descending);

Age is a consequence of experience
 
Strange. This isn't in my list?

Age is a consequence of experience
 
Sorry, my mistake, thats for a DataGrid as opposed to a datagridview.

In order to use automatic sorting in a dgv the column must be a text box column. Also the dgv SelectionMode cannot be set to ColumnHeaderSelect or FullColumnSelect. I think you also need to set ColumnHeadersVisible to true.

Otherwise I cant work out why its not working!
 
I have also found that I am suppressing the error, which is

DataGridView control must be bound to an IBindingList object to be sorted.

Think I am going to have to look into this. I thought that sort was supported by default?

Age is a consequence of experience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top