Jump to content

Effortlessly sort columns in DBGrid & Datagrid??

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Andrern2000

Andrern2000

    Newbie

  • Members
  • Pip
  • 2 posts
Dim sortField As String
Dim sortString As String

sortField = DataGrid1.Columns(ColIndex).Caption
If InStr(Data1.Recordset.Sort, "Asc") Then
sortString = sortField & " Desc"
Else
sortString = sortField & " Asc"
End If
Data1.Recordset.Sort = sortString

That is the source code I got from MSDN..!

So I created both DBGrid and Datagrid, then assigned DBGrid to Data, and Datagrid to ADODC. I filled everything on Data and ADODC, and all of DBGrid & Datagrid displays the content of database. I used Biblio.mdb database then displaying table Author. Meaning all is well.

..but, when I clicked the head column, nothing happens.. I changed the trigger into Changing & ColResize. Then I change the column size and change the inside data. Nothing happens...

Anyone knows why?

Edited by Andrern2000, 28 October 2010 - 05:40 PM.
Getting source code from MSDN


#2
Andrern2000

Andrern2000

    Newbie

  • Members
  • Pip
  • 2 posts
The rst.Sort, in this case Data1.recordset.Sort, already contains "Author ASC" when clicked in the headcolumn, but still... cannot sort the whole data table..

Something strange happens,...

Private Sub Command1_Click()
Print DataGrid1.Columns(ColIndex)
Print DataGrid1.Columns(ColIndex).Caption
Print Adodc1.Recordset.Sort
End SubPosted Image

When I click the button, the DataGrid1.Columns(ColIndex) actually returns row index value instead of column index value.
Can someone help me?

Edited by Andrern2000, 28 October 2010 - 07:30 AM.
Additional info