Io ho inserito un popupmenu che apro sull'evento DataGrid1_HeadClick, ti posto il codice senza la gestione del popup, se comunque ti interessa chiedi.
L'esempio è in ADO, fai attenzione ai campi memo non si possono ordinare:
codice:
Private Prec As String
Private Rs As New ADODB.Recordset
Private Sub DataGrid1_HeadClick(ByVal ColIndex As Integer)
On Local Error GoTo errori
Valore = DataGrid1.Columns(ColIndex).Caption
If Rs.State = 1 Then Rs.Close
Rs.CursorLocation = adUseClient
If Prec = "DESC" Then
StrSql = "select * from Tabella order by " & Valore & " ASC"
Prec = "ASC"
Else
StrSql = "select * from Tabella order by " & Valore & " DESC"
Prec = "DESC"
End If
Rs.Open StrSql, Db, adOpenKeyset, adLockOptimistic
Set DataGrid1.DataSource = Rs
DataGrid1.Refresh
Exit Sub
errori:
If Err.Number = 3117 Then
MsgBox "Impossibile ordinare o effettuare ricerche su campi Memo", vbInformation, "Attenzione"
Else
MsgBox Err.Description, vbCritical, Err.Number
End If
End Sub
Spero sia chiaro, ciao.