griview data event, change sort order

Post your Gambas programming questions here.
Post Reply
bill-lancaster
Posts: 135
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

griview data event, change sort order

Post by bill-lancaster » Monday 26th July 2021 11:59am

I've been using the data event in gridview, the data source is a mysql database.
It all works fine.
When changing the sort order of a column in the database result, how is the Data event triggered?

Code: Select all

Public Sub Button1_Click()
  hResultMaster = hConn.Find("master", "ORDER BY Narrative")
  FMain.Activate
End
The gridview display is empty after this action.

In other words, if the order of records in hResultMaster is changed, how to invoke the Data event to reflect this change?

bill-lancaster
Posts: 135
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Re: griview data event, change sort order

Post by bill-lancaster » Monday 26th July 2021 12:49pm

This seems to do the trick.

Code: Select all

Public Sub gdvMaster_Sort()
Dim sOrder As String
  If gdvMaster.Columns.Ascending Then 
    sOrder = gdvMaster.Columns[gdvMaster.Columns.Sort].Text 
  Else 
    sOrder = gdvMaster.Columns[gdvMaster.Columns.Sort].Text & " DESC"
  Endif
  hResultMaster = hConn.Find("master", "ORDER BY " & sOrder)
  gdvMaster.Clear

Post Reply