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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSFlexGrid - Sort by Column Clicked 1

Status
Not open for further replies.

kmcclung

Programmer
Nov 20, 2001
120
0
0
US
I'm sure there are posts out there but the search not available I can't find anything so I apologize if this has been answered in the past...

I have a MSFlexGrid that is sorted by a date - records are sorted by date in the SQL query to retreive them. They are put into a collection that is then used to populate the grid. However, I'd like the user to be able to click on the Name column and have the grid re-sort the records by name - similar to Excel.

Any ideas?
 
Try to use RecordSet.sort method and tie it to click event. There are some other properties you have to set for the sort method, but there excellent documentation at microsoft knowledge base.
 
Try this -

Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Static blAscending As Boolean

If Button = vbLeftButton Then
If MSFlexGrid1.Rows > 1 And MSFlexGrid1.MouseRow = 0 Then 'There is something more than just Headings.
If blAscending Then
MSFlexGrid1.Sort = flexSortStringAscending
blAscending = True
Else
MSFlexGrid1.Sort = flexSortStringDescending
blAscending = False
End If
End If
End If

End Sub

You'll need to place additional code to ensure you are sorting the correct column but this should get you a long way towards your objective.
 
Sorry, please correct one of the lines in my previous example to read -

.
.
If Not blAscending Then
.
.

Please ensure the "Not" is added to this line.
 
Thanks ShaneA! That is exactly what I needed!!
 
I thought I'd give this one a star. It was exactly what I was looking for.

***You can't change your past, but you can change your future***
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top