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

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
stam
Posts: 3072
Joined: Sun Jun 04, 2006 9:39 pm

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

Post by stam » Mon Oct 19, 2020 12:12 pm

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?
Last edited by stam on Tue Oct 20, 2020 2:01 am, edited 1 time in total.

stam
Posts: 3072
Joined: Sun Jun 04, 2006 9:39 pm

Re: Programmatically trigger a mouseUp in a data grid?

Post by stam » Mon Oct 19, 2020 12:53 pm

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...

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 324
Joined: Sat Aug 16, 2008 9:48 am
Contact:

Re: Programmatically trigger a mouseUp in a data grid?

Post by SWEdeAndy » Mon Oct 19, 2020 1:25 pm

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?
Andreas Bergendal
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
(WIS_WebDeployHelper, WIS_ScriptDependencies, WIS_BrowserAnimation)
WhenInSpace: https://wheninspace.com

stam
Posts: 3072
Joined: Sun Jun 04, 2006 9:39 pm

Re: Programmatically trigger a mouseUp in a data grid?

Post by stam » Mon Oct 19, 2020 1:34 pm

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?

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 324
Joined: Sat Aug 16, 2008 9:48 am
Contact:

Re: Programmatically trigger a mouseUp in a data grid?

Post by SWEdeAndy » Mon Oct 19, 2020 4:47 pm

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.
Andreas Bergendal
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
(WIS_WebDeployHelper, WIS_ScriptDependencies, WIS_BrowserAnimation)
WhenInSpace: https://wheninspace.com

Post Reply