The datagird has a .HeadClick method. Build your code there. I don't have the exact code with me, but I think this is right or pretty darn close.
** First place your original Select statement for the ado control in a string variable, let's say strSelect.
dgTest.HeadClick(ByVal ColIndex As Integer)
strSort as String
strSort = " order by " &
dgTest.Columns(ColIndex).DataField
adoControlTest.RecordSource = strSelect & strSort
adoControlTest.Refresh
This will retrieve the datafield that is related to the column that you had selected. Then build your order by clause(or you can just put concatenate it to the end of the select statement). Then by making it the new recordsource select and refresh your adoControl you will get the sort recordset by the column that you selected.
Please let me know if this helps and if you have any questions or concerns.
I find this to be an easy solution for your datagrid sort problem. I think it is very self-explanatory:
Private Sub dgrje_HeadClick(ByVal ColIndex As Integer)
Dim rs As ADODB.Recordset
Set rs = adorje.Recordset
If rs.Sort <> dgrje.Columns(ColIndex).DataField & " ASC" Then
rs.Sort = dgrje.Columns(ColIndex).DataField & " ASC"
Else
rs.Sort = dgrje.Columns(ColIndex).DataField & " DESC"
End If
End Sub
just curious, how do you grab the row that you clicked, so that you can grab the value of a colum on that row (for example, I am using datagrid as a generic view with partial data, I want to double click, and grab one of the field's number, so I can pass it to another dataform to show detailed information) Karl Blessing aka kb244{fastHACK}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.