DBGrid Sort

By | 2002-06-01

It is nice technique for dbgrid sorting.You
can sort Dbgrid Columns by clicking on the grid column header
in two ways ascending or descending.

Original Author: Adam Abas

Returns

Sorted Records in dbgrid.

Side Effects

No Idea,

API Declarations

Code

Option Explicit
Dim st As Boolean
***********************
Private Sub DBGrid1_HeadClick(ByVal ColIndex As Integer)
'Dbgrid Columns sort by clicking the grid header in two way ascending and descending
If st = True Then
DBGrid1.HoldFields
Data1.RecordSource = " Select * from Authors Order By " & DBGrid1.Columns(ColIndex).DataField
Data1.Refresh
DBGrid1.ReBind
Else
DBGrid1.HoldFields
Data1.RecordSource = " Select * from Authors Order By " & DBGrid1.Columns(ColIndex).DataField & " DESC "
Data1.Refresh
DBGrid1.ReBind
End If
st = Not st
End Sub

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.