Page 1 of 1

[SOLVED] Programmatically trigger a mouseUp in a data grid?

Posted: Mon Oct 19, 2020 12:12 pm
by stam
Hi all,
sorry for the beginner level question:

I have a data grid that is basically an index to populate other fields/data grids on a card.
When the user clicks on a the index data grid, a mouseUp handler in the behaviour script populates everything else.
So far, so good, everything works as expected.

The problem is restarting the app; no line in the index data grid is highlighted and often the information in the other fields/data grids is the previously held information, when ideally i'd like it to be the first index in the index data grid and the populated data to correspond to this.

I can set the dgHilitedLines of group "indexDataGrid" to 1 and the first line is indeed highlighted.
However the function to populate the card data (normally in the mouseUp handler of the behaviour script) won't run and sending/dispatching mouseUp to the index data grid does nothing, so although the line changes, the data in the card does not update.

Is there a way to programmatically select a line and trigger a mouseUp event for a line in the data grid?

Re: Programmatically trigger a mouseUp in a data grid?

Posted: Mon Oct 19, 2020 12:53 pm
by stam
As an aside, i also experimented adding a selectionChanged handler to the data grid. This works the same as the mouseUp handler in the DG's behaviour script (except now it triggers when moving the selection with arrow keys, which is prefereble i guess).

But i still can't trigger this by setting the dgHilitedLines property of the data grid...

Any advice would be most welcome...

Re: Programmatically trigger a mouseUp in a data grid?

Posted: Mon Oct 19, 2020 1:25 pm
by SWEdeAndy
I would put the handler that does the populating of other fields in the card script:

Code: Select all

command displayData pLine
   set the dgHilitedLines of group "YourDataGrid" to pLine -- This is redundant when clicking in the dg, but covers the automation case
   put the dgDataOfLine[pLine] of group "YourDataGrid" into tDataA
   
   put tDataA["theColumnYouWant"] into fld "theFieldWhereItGoes"
   -- etc, for all relevant fields
end displayData
Then in the mouseUp of the dataGrid just:

Code: Select all

on mouseUp
   put the dgHilitedLines of me into tLine
   displayData tLine
end mouseUp
And at openCard or wherever you initialize the app when opening it, you just do:

Code: Select all

displayData 1
to get it to select the first line AND populate the fields with it.

Would that do what you want to achieve?

Re: Programmatically trigger a mouseUp in a data grid?

Posted: Mon Oct 19, 2020 1:34 pm
by stam
Thanks Andy, that's very helpful...

I had worked around it just now actually - the selectionChanged handler would actually fire but i hadn't provided current and previous indexes as parameters so it did nothing :D

so now my code is located in the data grid's script rather than it's behaviour script:

Code: Select all

put the dgHilitedIndex of group "indexDataGrid" into tOldIndex
set the dgHilitedLine of group "indexDataGrid" to 1
put the dgHilitedIndex of group "indexDataGrid" into tNewIndex

dispatch "selectionChanged" to group "indexDataGrid" with tNewIndex,tOldIndex
you make a good point about separating the populating the other fields from the behaviour script -- that's what happens when you code at 3 am...

But back to my original question (not really relevant any more but more for my curiosity) - can you dispatch a mouseUp event to the script of a data grid?

Re: Programmatically trigger a mouseUp in a data grid?

Posted: Mon Oct 19, 2020 4:47 pm
by SWEdeAndy
stam wrote:
Mon Oct 19, 2020 1:34 pm
But back to my original question (not really relevant any more but more for my curiosity) - can you dispatch a mouseUp event to the script of a data grid?
To the datagrid as a whole, yes. If you've added a mouseUp handler to its script. To simulate a mouseclick on a specific row, I guess you'd have to dispatch the mouseUp to the row group of the dg, for the behaviour script to pick it up. (Someone better than me at the inner workings of datagrids may have a better answer.) But as mentioned above, I would opt for a solution that gives more flexible control of both action and view update, adapting to the situation.