Page 1 of 1
How to programmatically select a datagrid
Posted: Mon May 12, 2025 12:35 pm
by CAsba
HI all,
I have three dg's on a card. I can select a dg by clicking on it and then using up and down arrows to select a line. But, I want to enable the user to use the keyboard instead of the mouse. Is it possible to programmatically 'click' on the dg to enable the user to use the up and down keys ?
Re: How to programmatically select a datagrid
Posted: Mon May 12, 2025 2:34 pm
by dunbarx
Hi,
You could
Code: Select all
click at the loc of grp "yourDatagrid".
.
That would focus on the DG you want. But once you get there, how do you navigate to the "cell" or row you are interested in? Something like:
Code: Select all
click at the loc of fld "col 1 0002" of grp "yourDatagrid"
click at the loc of fld "col 1 0002" of grp "yourDatagrid"
That will at least get you to the second row. I bet if you played around a bit, you could get to a particular field, in the same way as if you double-clicked on that field.
Obviously I am no expert with DG's, though I do use them now and then.
Craig
Re: How to programmatically select a datagrid
Posted: Tue May 13, 2025 1:37 am
by FourthWorld
See the dgHilitedLines property.
Re: How to programmatically select a datagrid
Posted: Wed May 14, 2025 9:50 am
by CAsba
Many thanks.
Re: How to programmatically select a datagrid
Posted: Wed May 14, 2025 1:48 pm
by dunbarx
Richard.
A problem. Although something like:
Code: Select all
set the DGHilitedLines of grp 1 to 3
works fine, it does not "select" the DG itself.That means that the arrowKeys are not able to do any navigation. Clicking on a line in the DG does.
Craig
Re: How to programmatically select a datagrid
Posted: Wed May 14, 2025 4:06 pm
by FourthWorld
dunbarx wrote: ↑Wed May 14, 2025 1:48 pm
Richard.
A problem. Although something like:
Code: Select all
set the DGHilitedLines of grp 1 to 3
works fine, it does not "select" the DG itself.That means that the arrowKeys are not able to do any navigation. Clicking on a line in the DG does.
If he doesn't want the user to have to click on an object he wants to have focus, he'll have to handle events at the card or stack level and set the focus in response to the arrow key handler there.
The focus can be set with the "focus" command.
Re: How to programmatically select a datagrid
Posted: Wed May 14, 2025 5:13 pm
by dunbarx
Richard.
Setting the focus of a DG does not, er, focus it. In fact, if I have a card with a single field, focussing on it:
does not do what the dictionary says it does, which to, er, focus on it and place a blinking cursor there. I have to click on the field to do that.
I never use the focus command. This may be a good reason to still not.
Craig
Re: How to programmatically select a datagrid
Posted: Wed May 14, 2025 5:17 pm
by dunbarx
AHA.
It does work from a button, just not from the message box. I see a short-lived "blink" in the fld from msg, but nothing changes.
Craig
Re: How to programmatically select a datagrid
Posted: Thu May 15, 2025 3:06 am
by PaulDaMacMan
dunbarx wrote: ↑Wed May 14, 2025 5:13 pm
Richard.
Setting the focus of a DG does not, er, focus it. In fact, if I have a card with a single field, focussing on it:
does not do what the dictionary says it does, which to, er, focus on it and place a blinking cursor there. I have to click on the field to do that.
I never use the focus command. This may be a good reason to still not.
Craig
Focusing and selecting are two different things.
I usually do this as a combo something like:
Code: Select all
focus on fld 1
select char -1 to -1 of fld 1
I'm usually doing that with list fields so..
The Datagid is different animal, a library / template stack with groups thing, so I think you would need to add to the chunk expression with something like 'select char tMyCharPosition+1 of fld 1 of group tMyDataGrid'.
Re: How to programmatically select a datagrid
Posted: Thu May 15, 2025 3:15 am
by PaulDaMacMan
I definitely have a working example somewhere, of a Datagrid that's entirely navigable from a keyboard, arrowKeys, tabKey etc. I'll try to dig it out and post it if I get a minute.