auto sort specific column datagridview

thejeraldo

Well-known member
Joined
Jun 9, 2009
Messages
70
Location
Philippines
Programming Experience
1-3
how do i automatically sort a specific column of a datagridview ascendingly? i just want my datagridview to sort automatically on a particular column everytime it fills up again. thanks a lot! :)
 
This is the type of question that makes it obvious that you haven't looked for yourself first. You want to sort a DataGridView by a specific column?

1. You go to the MSDN library and look up the DataGridView.

datagridview - MSDN Search

2. You can click the first result to go to the documentation for the class.

DataGridView Class (System.Windows.Forms)

3. You can then click on the link to go to the member listing.

DataGridView Members (System.Windows.Forms)

4. You can then look down the list of members and you'll soon see that there's a Sort method, that should obviously pique your interest, so you can click that link.

DataGridView.Sort Method (System.Windows.Forms)

5. Reading that page you can see that there's an overload of Sort that takes a column, which seems like exactly what you want.

DataGridView.Sort Method (DataGridViewColumn, ListSortDirection) (System.Windows.Forms)

Getting to that point should be even easier if you have installed the MSDN documentation locally, which everyone should.

When what you want to do takes a combination of various types and members then it's often quite hard to work out how to find that combination. When all it takes is a single method call that you could find in the documentation for the class that you already know you're using, you should always find that for yourself because you should always be reading the appropriate documentation first.
 
sorry bout that. i actually tried doing it but failed so i thought it was kinda hard.. this is what i did but had no luckl:
VB.NET:
DGEmp.Columns("ColLName").SortMode = DataGridViewColumnSortMode.Programmatic
        DGEmp.Columns("ColLName").HeaderCell.SortGlyphDirection = SortOrder.Ascending

but the 5th link you sent me did it. thanks.
VB.NET:
DGEmp.Sort(DGEmp.Columns("ColLName"), System.ComponentModel.ListSortDirection.Ascending)
 
Back
Top