[Gambas-user] DataView Help
T Lee Davidson
t.lee.davidson at gmail.com
Wed Jul 12 22:01:37 CEST 2023
On 7/12/23 15:14, Benoit Minisini wrote:
> Le 12/07/2023 à 01:14, T Lee Davidson a écrit :
>> On 7/11/23 08:40, Gianluigi wrote:
>>> I still couldn't select the correct row though, I always end up selecting the last one
>>
>> It appears that DataView.Find assumes the sort order of the view is by `students_id`. But, it isn't always. In fact, when the
>> application launches, the view is sorted by `surname` descending.
>
> The Find() method takes the current sort order defined in the DataSource by the DataView control.
Hmmm, I don't find any sort order property in either DataSource or Dataview.
> In last commit https://gitlab.com/gambas/gambas/-/commit/13e65fa01dcf315357bf1d2f3577f0fa9d06b3ea, I fixed the DataSource Find()
> and FindNext() methods, and propagate them to DataView and DataBrowser.
>
> As LastInsertId may not be reliable, one have to use the DataView.Find() method to find the index of the last inserted record,
> knowing the primary keys of that record.
>
> Now, following what I just said, I will try to add a method that finds the index of the last inserted record automagically.
That sounds like it might be quite helpful.
DataView's automatic handling of column sorting is quite nice. Would it be possible to expose TableView's Sort event to
DataView? With that, a developer could possibly determine that sort order had changed and which column header was clicked. And,
perhaps using 'Stop Event' would allow for custom sorting although that might be used, like, never.
I don't know exactly what needed to be fixed, nor what the correct behavior will now be. But, for what Gianluigi wants to
accomplish, the following seems to work well:
[code]
Public Sub btnSave_Click()
Dim iLastInsertId As Integer
DataSource1.Save
iLastInsertId = DataSource1.Connection.LastInsertId
DataView1.MoveFirst
While DataView1.Current[0] <> iLastInsertId
DataView1.MoveNext
Wend
End
[/code]
Unfortunately, though, the current record does not follow a change in sort order.
--
Lee
More information about the User
mailing list