How to drop Popup Menus in a Data Grid on tab/return?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 235
- Joined: Thu Jul 01, 2010 11:50 am
How to drop Popup Menus in a Data Grid on tab/return?
I have a data grid table with three columns. The first column is normal text, the second two are Popup Menu controls. I figured out how to tab from Col 1 to Col 2 and get the Popup Menu in Col 2 to drop automatically. But here's what I *can't* do:
(1) When the user makes a selection from Col 2's popup menu, automatically drop the popup menu in Col 3.
(2) When the user presses the tab key while Col 2's popup menu is dropped, automatically drop the popup menu in Col 3.
(3) When a popup menu is dropped, highlight the current value from the table in the list. For example, if the label of the button/menu is "Green", and the menu contents are "Red", "Green", "Blue", when the menu is dropped the user sees those three choices, but nothing in the menu is highlighted.
Any ideas? Thanks for your help!
(1) When the user makes a selection from Col 2's popup menu, automatically drop the popup menu in Col 3.
(2) When the user presses the tab key while Col 2's popup menu is dropped, automatically drop the popup menu in Col 3.
(3) When a popup menu is dropped, highlight the current value from the table in the list. For example, if the label of the button/menu is "Green", and the menu contents are "Red", "Green", "Blue", when the menu is dropped the user sees those three choices, but nothing in the menu is highlighted.
Any ideas? Thanks for your help!
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: How to drop Popup Menus in a Data Grid on tab/return?
You can use ColumnControlOfIndex() (appears in API page) to get a reference to the control being used in a column.
Here is an example script that could be used in a column behavior script that would get the control used to render a particular column:
Here is an example script that could be used in a column behavior script that would get the control used to render a particular column:
Code: Select all
put ColumnControlOfIndex("cost", the dgIndex of me) into theColumnControl
if theColumnControl is not empty then
## assumes you used a group as your custom column template
put the menuhistory of button 1 of theColumnControl into theSelectedLine
## click on the menu to display it
click button 1 at the loc of button 1 of theColumnControl
end if
Last edited by trevordevore on Mon Aug 23, 2010 2:12 pm, edited 1 time in total.
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
-
- Posts: 235
- Joined: Thu Jul 01, 2010 11:50 am
Re: How to drop Popup Menus in a Data Grid on tab/return?
Thank you very much for this. How exactly do I call this? Which handler does it go in? I tried putting it in the menuPick handler of the popup control for Column 1, but after I choose an option from that control, the popup control in Column 2 doesn't drop. Also, I had to remove the word "the" before "ColumnControlOfIndex" to stop a script error.
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: How to drop Popup Menus in a Data Grid on tab/return?
The code snippet would work inside of the behavior script for a column. The code is untested but I made a slight modification so that the button click is at the loc of button 1 of theColumnControl rather than the loc of theColumnControl.
One way to troubleshoot the code would be to to use "put" statements to output data to the message box. You can ensure that the code is getting executed at all and whether or not the values being put into the variables are what you expect.
One way to troubleshoot the code would be to to use "put" statements to output data to the message box. You can ensure that the code is getting executed at all and whether or not the values being put into the variables are what you expect.
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
-
- Posts: 235
- Joined: Thu Jul 01, 2010 11:50 am
Re: How to drop Popup Menus in a Data Grid on tab/return?
I still don't understand. I asked which handler your code goes in, and you said "the behavior script for a column". If I understand the terminology correctly, that's apples and oranges. I think the behavior script for the column is what I get when I go to Columns > Col1 > Column Behavior in the Property Inspector. If I do that, I get a script with a bunch of handlers. Again, into which handler do I put your code? Or are you saying the code should work naked, outside a handler? (It doesn't work for me that way.)
"put" statements aren't going to help me if I don't even know where the code is supposed to go.
"put" statements aren't going to help me if I don't even know where the code is supposed to go.
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: How to drop Popup Menus in a Data Grid on tab/return?
Sorry, I didn't provide a function or command that could be called, just some code that would help you target a control in a column. As written, the code needs to be placed in the behavior script (because of the 'of me' reference) in a handler of your choosing. No code can work outside of a handler in Rev.
If you want the code to be executed on menuPick then you could:
a) Write a command in the column 1 behavior script that contains the example code I provided. Call that command from the menuPick handler of your button.
b) Rewrite the example I provided so that it will work in the menuPick handler of the button. Try changing 'the dgIndex of me' to 'the dgIndex of the dgDataControl of me'.
If you want the code to be executed on menuPick then you could:
a) Write a command in the column 1 behavior script that contains the example code I provided. Call that command from the menuPick handler of your button.
b) Rewrite the example I provided so that it will work in the menuPick handler of the button. Try changing 'the dgIndex of me' to 'the dgIndex of the dgDataControl of me'.
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
-
- Posts: 235
- Joined: Thu Jul 01, 2010 11:50 am
Re: How to drop Popup Menus in a Data Grid on tab/return?
Thank you very much for your continued help with this.
I checked and I'm apparently unable to get menuPick to fire. I put this in the Column Behavior script:
But nothing happens when I choose a new item from the popup menu.
I put a similar command into the actual button in the row template, but same deal -- no alert comes up when I choose an option from the menu.
What am I doing wrong?
I checked and I'm apparently unable to get menuPick to fire. I put this in the Column Behavior script:
Code: Select all
on menuPick pItemName
answer "Test from column behavior script"
end menuPick
I put a similar command into the actual button in the row template, but same deal -- no alert comes up when I choose an option from the menu.
What am I doing wrong?
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: How to drop Popup Menus in a Data Grid on tab/return?
My guess is that you are trapping menuPick in the menu control. Edit the script of the menu control and see if you've defined a menuPick handler that does not pass the message down the message path.
I just put a test stack together with two columns: Col 1 and Col 2. In the Col 1 behavior script I added this:
This almost worked. I found a bug in the data grid which I just fixed for the next Rev release. ColumnControlOfIndex is returning a value that looks like this:
This is a shortened control reference that is used internally by the data grid. This control reference will only work in the data grid group script itself. There is a workaround though - just delete the ' of me' from the control reference.
Here is the code that works for me:
I just put a test stack together with two columns: Col 1 and Col 2. In the Col 1 behavior script I added this:
Code: Select all
on menuPick pItemName
put ColumnControlOfIndex("col 2", the dgIndex of me) into theColumnControl
if theColumnControl is not empty then
## assumes you used a group as your custom column template
put the menuhistory of button 1 of theColumnControl into theSelectedLine
## click on the menu to display it
click button 1 at the loc of button 1 of theColumnControl
end if
end menuPick
Code: Select all
control id 1020 of me
Here is the code that works for me:
Code: Select all
on menuPick pItemName
put ColumnControlOfIndex("col 2", the dgIndex of me) into theColumnControl
replace " of me" with empty in theColumnControl ## get rid of ' of me' reference
if theColumnControl is not empty then
## assumes you used a group as your custom column template
put the menuhistory of button 1 of theColumnControl into theSelectedLine
## click on the menu to display it
click button 1 at the loc of button 1 of theColumnControl
end if
end menuPick
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
-
- Posts: 235
- Joined: Thu Jul 01, 2010 11:50 am
Re: How to drop Popup Menus in a Data Grid on tab/return?
I deleted the entire menuPick handler from the menu control, leaving only the menuPick handler in the Column Behavior script, but still nothing happens (no alert box) when I choose a new item from the menu.My guess is that you are trapping menuPick in the menu control. Edit the script of the menu control and see if you've defined a menuPick handler that does not pass the message down the message path.
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: How to drop Popup Menus in a Data Grid on tab/return?
Did you refresh the data grid controls using the button at the bottom of the property inspector? If not then the old controls would still be used in the data grid and you wouldn't see a change.
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
-
- Posts: 235
- Joined: Thu Jul 01, 2010 11:50 am
Re: How to drop Popup Menus in a Data Grid on tab/return?
Thanks, I didn't know I had to Refresh for changes in controls. (I thought it was just for changes in data.) After installing your script and refreshing, it works perfectly. Thanks again!
When the menu in Col1 is dropped, is there a way to drop the menu in Col2 if the user presses the Tab key? In my app the user might want to leave the previous selected value in Col1 and proceed straight to Col2. I tried adding an "on tabkey" handler to the Column Behavior script, then to the script of the menu control itself (refreshing the datagrid between each attempt), but it doesn't seem to fire.
When the menu in Col1 is dropped, is there a way to drop the menu in Col2 if the user presses the Tab key? In my app the user might want to leave the previous selected value in Col1 and proceed straight to Col2. I tried adding an "on tabkey" handler to the Column Behavior script, then to the script of the menu control itself (refreshing the datagrid between each attempt), but it doesn't seem to fire.
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: How to drop Popup Menus in a Data Grid on tab/return?
Revolution doesn't have a concept of shared controls, only shared scripts. This means that when you update anything other than the behavior script in your column or row template you need to refresh the data grid to see the changes. If Revolution could share controls like it does behavior scripts then you wouldn't need to do this.
The tabKey message is going to be sent to whichever control has focus. My guess is that the data grid has focus and not the menu. Some things to try:
1) If you are only running your project on Windows then set the traversalOn of the menu button to true. The button can then get focus and tabKey will be sent to it. On OS X menu buttons cannot have focus so this won't work.
2) Add a graphic that has traversalOn set to true to your column template. Explicitly focus on it when showing the menu using 'focus on graphic 1 of theColumnControl. Your column would now contain the control that has focus and tabKey could be processed by the column behavior script.
3) Try processing the tabKey message in the data grid group script.
The tabKey message is going to be sent to whichever control has focus. My guess is that the data grid has focus and not the menu. Some things to try:
1) If you are only running your project on Windows then set the traversalOn of the menu button to true. The button can then get focus and tabKey will be sent to it. On OS X menu buttons cannot have focus so this won't work.
2) Add a graphic that has traversalOn set to true to your column template. Explicitly focus on it when showing the menu using 'focus on graphic 1 of theColumnControl. Your column would now contain the control that has focus and tabKey could be processed by the column behavior script.
3) Try processing the tabKey message in the data grid group script.
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
-
- Posts: 235
- Joined: Thu Jul 01, 2010 11:50 am
Re: How to drop Popup Menus in a Data Grid on tab/return?
I'm developing on a Mac, but I'd like to deploy in both Mac and Windows environments.
I tried option #2. I added a graphic and set its traversalOn to true, and set the script of the popup menu's "on mousedown" to give the focus to that graphic. I checked that it received the focus properly by setting "on focusin" for the graphic to "put the milliseconds". So far so good. I then added an "on tabkey" handler to the Column Behavior script ("answer 'test'"), but nothing happened when I pressed on the popup menu to drop it.
And then it just broke. Now when I press on the popup menu to drop it, I get a script error on the last line of the script for the popup menu:
(Chunk: error in object expression, char 10)
This code worked fine for me a minute ago.
I had the same problem earlier which the dataGrid just suddenly broke, so I went through the painstaking process of deleting the DataGrid and creating another one from scratch. Now this one is broken too.
I tried option #2. I added a graphic and set its traversalOn to true, and set the script of the popup menu's "on mousedown" to give the focus to that graphic. I checked that it received the focus properly by setting "on focusin" for the graphic to "put the milliseconds". So far so good. I then added an "on tabkey" handler to the Column Behavior script ("answer 'test'"), but nothing happened when I pressed on the popup menu to drop it.
And then it just broke. Now when I press on the popup menu to drop it, I get a script error on the last line of the script for the popup menu:
Code: Select all
on mousedown
put ColumnControlOfIndex("Account1", the dgIndex of me) into theColumnControl
replace " of me" with empty in theColumnControl ## get rid of ' of me' reference
focus on graphic 1 of theColumnControl
end mousedown
This code worked fine for me a minute ago.
I had the same problem earlier which the dataGrid just suddenly broke, so I went through the painstaking process of deleting the DataGrid and creating another one from scratch. Now this one is broken too.
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: How to drop Popup Menus in a Data Grid on tab/return?
The data grid isn't broken, it is just that the script is generating an error. You don't check in your code to verify that theColumnControl has a meaningful value. What if ColumnControlOfIndex returned empty?
You mention that your code is in the popup menu. If so then the dgIndex of me isn't going to return a valid value. You need to use the dgIndex of the dgDataControl of me since the dgIndex is a property of the column control, not the popup menu within the column control.
Also, make sure and pass mouseDown so the data grid can process it.
As for tabKey, it doesn't look like the tabKey message gets sent while a menu is displayed on OS X. I just dragged an option menu onto a card and put a tabKey handler in the button and the card and neither receives the message while the option menu is open.
You mention that your code is in the popup menu. If so then the dgIndex of me isn't going to return a valid value. You need to use the dgIndex of the dgDataControl of me since the dgIndex is a property of the column control, not the popup menu within the column control.
Also, make sure and pass mouseDown so the data grid can process it.
As for tabKey, it doesn't look like the tabKey message gets sent while a menu is displayed on OS X. I just dragged an option menu onto a card and put a tabKey handler in the button and the card and neither receives the message while the option menu is open.
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
-
- Posts: 235
- Joined: Thu Jul 01, 2010 11:50 am
Re: How to drop Popup Menus in a Data Grid on tab/return?
Okay, let me back up here, so you can see if my basic ideas are sound before I waste any more of your time. I'm trying to write a simple Accounting application, for my own use, and also to market as a product if I'm able to produce something useful. Accounting is data-entry intensive and all good Accounting apps make it easy to enter data with only the keyboard and not the mouse. In particular, I'm trying to replicate the interface I used in FileMaker for years, where each record was on a single line, and I could easily tab between fields. Two of the fields were pop-up menus. It looks like it's impossible for me to tab out of a field with a dropped menu in Rev, so probably FileMaker was using its own menu-drop routine and not borrowing from the OS.
My idea for getting around this problem is to not automatically drop the menu in the Account1 and Account2 fields. Instead, I'll just allow the field to open up for editing as usual, so the user can see the existing value (if any), and then if the user presses Tab, then they'll go to the next field without any scripting necessary. However, if they press a letter key, then that will show the menu and drop it, so they can then navigate to the option they want by more typing. The problem with this is that I'm guessing the first keystroke (to drop the menu) will be "lost", and won't actually navigate among the options in the menu.
So I could tweak the interface from there. Most of the time the user will be entering new data, rather than editing existing data. So when a field is opened without a value, I could drop the menu automatically, so the user can start selecting an option with the keyboard immediately. The inability to navigate out with the tab key isn't a big issue, because if the field has no value, the user is certainly going to want to choose a value here, not skip that field. If they really do need to tab out, then pressing Esc to kill the menu, and then Tab to go to the next field would be good enough. By dropping the menu automatically when the user is likely to be choosing an option from the menu, their first keystroke won't be wasted.
But if the user tabs to the field and it does already have a value, then likely the user won't be changing the value, so I won't drop the menu automatically, so the user will be able to tab out of the field to the next one. If they do want to change the value, then they'll waste their first (letter) keystroke to drop the menu. So the first keystroke will be wasted only in those rare times when the user is editing an existing value rather than entering a new value.
Does the above seem reasonable? If so, then I hope I can ask some follow-up questions about implementation. I've been trying to trap messages without success.
My idea for getting around this problem is to not automatically drop the menu in the Account1 and Account2 fields. Instead, I'll just allow the field to open up for editing as usual, so the user can see the existing value (if any), and then if the user presses Tab, then they'll go to the next field without any scripting necessary. However, if they press a letter key, then that will show the menu and drop it, so they can then navigate to the option they want by more typing. The problem with this is that I'm guessing the first keystroke (to drop the menu) will be "lost", and won't actually navigate among the options in the menu.
So I could tweak the interface from there. Most of the time the user will be entering new data, rather than editing existing data. So when a field is opened without a value, I could drop the menu automatically, so the user can start selecting an option with the keyboard immediately. The inability to navigate out with the tab key isn't a big issue, because if the field has no value, the user is certainly going to want to choose a value here, not skip that field. If they really do need to tab out, then pressing Esc to kill the menu, and then Tab to go to the next field would be good enough. By dropping the menu automatically when the user is likely to be choosing an option from the menu, their first keystroke won't be wasted.
But if the user tabs to the field and it does already have a value, then likely the user won't be changing the value, so I won't drop the menu automatically, so the user will be able to tab out of the field to the next one. If they do want to change the value, then they'll waste their first (letter) keystroke to drop the menu. So the first keystroke will be wasted only in those rare times when the user is editing an existing value rather than entering a new value.
Does the above seem reasonable? If so, then I hope I can ask some follow-up questions about implementation. I've been trying to trap messages without success.
Last edited by MichaelBluejay on Thu Oct 03, 2019 2:52 pm, edited 1 time in total.