How to drop Popup Menus in a Data Grid on tab/return?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

MichaelBluejay
Posts: 235
Joined: Thu Jul 01, 2010 11:50 am

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by MichaelBluejay » Sun Sep 26, 2010 5:58 am

Thank you very much for your continued help. Since you've been helping me on a volunteer basis, I'd like to send you something for your trouble. Can I send it to the support email address at Blue Mango?

Here is the code from my Custom Field Editor Behavior script. I think you're right, the only thing that's different is the click to drop the popup menu, and if I comment out the "click button..." line then the old field editor does get closed properly.

Code: Select all

on tabKey
   put the dgTargetKey of me into currentColumn
   if currentColumn is "Description" or currentColumn is "Account1" then
      if currentColumn is "Description" then put "Account1" into nextColumn else put "Account2" into nextColumn
      put ColumnControlOfIndex(nextColumn, the dgTargetIndex of me) into theColumnControl
      replace " of me" with empty in theColumnControl ## get rid of ' of me' reference
      if theColumnControl is not empty then
         put GetDataOfIndex(the dgTargetIndex of me,"Account1")
         send "DeleteFieldEditorAndOpenNext" to the dgControl of me in 0 seconds
         click button 1 at the loc of button 1 of theColumnControl
      end if
   else if the autotab of me then
      send "DeleteFieldEditorAndOpenNext" to the dgControl of me in 0 seconds
   else
      pass tabkey
   end if
end tabKey

trevordevore
VIP Livecode Opensource Backer
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?

Post by trevordevore » Fri Oct 01, 2010 1:04 pm

Sorry for the delay Michael. No need to send anything, though I appreciate the offer. If you really want to send money my way you can always buy ScreenSteps, my company's documentation software :-)

Looking at your code, the problem may be that the click is happening before the new cell is actually opened for editing (you are using send in time with DeleteFieldEditorAndOpenNext). As another approach, you tried the following:

1) Rather than clicking on the button in the tabKey message, try setting a property of the data grid:

Code: Select all

send "DeleteFieldEditorAndOpenNext" to the dgControl of me in 0 seconds
set the uDisplayMenuWhenCellIsEdited of the dgControl of me to true ## this is the line where you previously tried clicking
2) Customize the behavior of your columns that should display the drop-down menu and in the EditValue message perform the click. Here is a lesson that talks about EditValue:

http://lessons.runrev.com/spaces/lesson ... -It-Opens-

And you can read up on it in the API section:

http://lessons.runrev.com/spaces/lesson ... a-Grid-API

Code: Select all

on EditValue
    if the uDisplayMenuWhenCellIsEdited of the dgControl of me is true then
        click button 1 at the loc of button 1 of me
        set the uDisplayMenuWhenCellIsEdited of the dgControl of me to false ## reset
    end if
end EditValue
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

MichaelBluejay
Posts: 235
Joined: Thu Jul 01, 2010 11:50 am

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by MichaelBluejay » Sat Nov 27, 2010 8:30 am

Thank you for your continued help. I had to put this project on the shelf for a while but I'm trying to get back to it. By the way, on Oct. 19 I sent you a virtual Kiva gift card to the support email address at Blue Mango, but Kiva informs me that it hasn't been redeemed yet. If the message that Kiva sent with the gift card # is lost then I can send it to you, just let me know how I should do that. You can write me directly at replies/at/michaelbluejay.com.

Continuing on my project, thanks to your help, I'm now able to tab from a column with a plain text field to a column with a popup menu, and have the popup automatically drop. After selecting an item from the popup menu, I'd like to tab to the next column, but pressing the tab key takes me out of the Data Grid and into another field on the card. I know that the Custom Field Editor script isn't seeing the tab because I put "put the seconds" into the "on tabKey" handler and nothing is showing up when I press the tab key.

I see two possible solutions but I don't know how to implement them. First, I could call EditFieldText from the "on menuPick" handler that's in the Column Behavior Script, so I can open a field for editing, so the Custom Field Editor script will see the tab key. But I don't know how to get the parameters to pass to EditFieldText.

Or, in the "on menuPick" handler in the Column Behavior script, I could hard-code the code that moves to the next field, but I tried that and it didn't work. The code I used was:

Code: Select all

send "DeleteFieldEditorAndOpenNext" to the dgControl of me in 0 seconds
set the CheckForMenuDrop of the dgControl of me to true
I'm guessing that "me" doesn't refer to the right thing when it's in the "on menuPick" handler.

How would you suggest I get the ability to tab to the next column? Thank you very much for your help.

Zryip TheSlug
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 163
Joined: Tue Jan 26, 2010 10:15 pm
Contact:

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by Zryip TheSlug » Sat Nov 27, 2010 5:40 pm

MichaelBluejay wrote:Thank you for your continued help. I had to put this project on the shelf for a while but I'm trying to get back to it. By the way, on Oct. 19 I sent you a virtual Kiva gift card to the support email address at Blue Mango, but Kiva informs me that it hasn't been redeemed yet. If the message that Kiva sent with the gift card # is lost then I can send it to you, just let me know how I should do that. You can write me directly at replies/at/michaelbluejay.com.

Continuing on my project, thanks to your help, I'm now able to tab from a column with a plain text field to a column with a popup menu, and have the popup automatically drop. After selecting an item from the popup menu, I'd like to tab to the next column, but pressing the tab key takes me out of the Data Grid and into another field on the card. I know that the Custom Field Editor script isn't seeing the tab because I put "put the seconds" into the "on tabKey" handler and nothing is showing up when I press the tab key.

I see two possible solutions but I don't know how to implement them. First, I could call EditFieldText from the "on menuPick" handler that's in the Column Behavior Script, so I can open a field for editing, so the Custom Field Editor script will see the tab key. But I don't know how to get the parameters to pass to EditFieldText.

Or, in the "on menuPick" handler in the Column Behavior script, I could hard-code the code that moves to the next field, but I tried that and it didn't work. The code I used was:

Code: Select all

send "DeleteFieldEditorAndOpenNext" to the dgControl of me in 0 seconds
set the CheckForMenuDrop of the dgControl of me to true
I'm guessing that "me" doesn't refer to the right thing when it's in the "on menuPick" handler.

How would you suggest I get the ability to tab to the next column? Thank you very much for your help.
Hi Michael,

I have not followed all the thread but it seems that with the help of Trevor, you have changed the FieldEditor behavior. The FieldEditor behavior is invoked when you edit text by using a message like EditText.
In your case, when you leave the content of a text cell to go in a popup cell, you have changed the FieldEditor to open the menu.
Internally when you invoke the DeleteFieldEditorAndOpenNext, the engine send an EditValue to the next column. In the EditValue you have placed a click statement to open the menu. However in the popup cell you have no field editor because you not invoke it by using an EditFieldText message. EditFieldText are usable when the cell contains a field.

I'm far to have the knowledge of Trevor, but here is a possible solution. This solution consists to let know to the datagrid that you used a menu control in a cell and manage the tab in this special case, inside the datagrid group.

1) Create a new property in your datagrid group script:

Code: Select all

local lTabToColumn

setProp uCurrentColumnWasNotField pTheCurrentColumn
   put pTheCurrentColumn into lTabToColumn
end uCurrentColumnWasNotField

getProp uCurrentColumnWasNotField
   return lTabToColumn
end uCurrentColumnWasNotField
This property will take the name of the column you need to manage the tabkey


2) In the menuPick handler located in the column behavior set the property with the name of the column

Code: Select all

on menuPick pTheMenuItem
     doYourStuff --  
     set the uCurrentColumnWasNotField of the dgControl of me to "myPopupColName1"
end menuPick

3) Add a tabkey handler in the datagrid group:

Code: Select all

on tabKey
   local tCurrentColumn, tCurrentRowNumber
   
   put the uCurrentColumnWasNotField of me into tCurrentColumn
   
   if (tCurrentColumn is not empty) then
      put item 1 of the dgHilitedLines of me into tCurrentRowNumber
      if (tCurrentColumn is "myPopupColName1") then
         put "Name" into tPreviousCol
         put "Col4" into tNextCol
      else if (tCurrentColumn is "myPopupColName2") then
         put "Col1" into tPreviousCol
         put "Col3" into tNextCol
      else
          codeWhatYouNeedHere --
      end if
      
      if (the shiftKey is "Down") then
         EditCell tPreviousCol,tCurrentRowNumber
      else
         EditCell tNextCol,tCurrentRowNumber
      end if
      
      set the uCurrentColumnWasNotField of me to empty
   else
      pass tabkey
   end if
end tabKey
In the variables tPreviousCol and tNextCol, give the name of the previous and next column you want after the choice of a value in a popup menu. Use tab to edit the next column, use shift + tab to edit the previous column


Regards,
Last edited by Zryip TheSlug on Sun Nov 28, 2010 12:08 am, edited 2 times in total.
TheSlug
http://www.aslugontheroad.com - Tutorials, demo stacks and plugins for LiveCode
Data Grid Helper - An intuitive interface for building LiveCode's Data Grids
Excel Library- Extends the LiveCode language for controlling MS Excel

MichaelBluejay
Posts: 235
Joined: Thu Jul 01, 2010 11:50 am

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by MichaelBluejay » Sat Nov 27, 2010 11:43 pm

Thank you very much for the detailed reply. This seems to be a lot more work than necessary. As I'd said, I figured that I could just make the call to edit the next cell with some code at the end of the menuPick handler in the Column Behavior script (CBS), but I didn't know what code to use. Now I do:

Code: Select all

   EditCell "Account2",the dgHilitedLines of me
So that one line of code seems to solve this problem.

By the way, the CBS already had a "command EditValue" handler, which confused me because I thought handlers always started with "on" or "function". I couldn't find anything in the User Guide about that. Is "command" equivalent to "on"?

Zryip TheSlug
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 163
Joined: Tue Jan 26, 2010 10:15 pm
Contact:

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by Zryip TheSlug » Sun Nov 28, 2010 12:29 am

MichaelBluejay wrote:Thank you very much for the detailed reply. This seems to be a lot more work than necessary. As I'd said, I figured that I could just make the call to edit the next cell with some code at the end of the menuPick handler in the Column Behavior script (CBS), but I didn't know what code to use. Now I do:

Code: Select all

   EditCell "Account2",the dgHilitedLines of me
So that one line of code seems to solve this problem.
Indeed, I understood that you want leave the "menu" cell with a tabkey, not that you want edit the cell of a column at the end of the execution of the menuPick handler. The script I sent and I have updated now is for preserving the tab key cycle. Sorry for the confusion. ;)
By the way, the CBS already had a "command EditValue" handler, which confused me because I thought handlers always started with "on" or "function". I couldn't find anything in the User Guide about that. Is "command" equivalent to "on"?
You're right, command and on are synonyms.

In my own habit, I prefer using:
- "on" for regular messages (sent by the LiveCode engine or the datagrid engine)
- "command" for foreign handlers


Regards,
TheSlug
http://www.aslugontheroad.com - Tutorials, demo stacks and plugins for LiveCode
Data Grid Helper - An intuitive interface for building LiveCode's Data Grids
Excel Library- Extends the LiveCode language for controlling MS Excel

MichaelBluejay
Posts: 235
Joined: Thu Jul 01, 2010 11:50 am

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by MichaelBluejay » Sun Nov 28, 2010 2:12 am

Indeed, I understood that you want leave the "menu" cell with a tabkey, not that you want edit the cell of a column at the end of the execution of the menuPick handler.
Actually, I want to do both. I really wasn't clear, sorry. After my first post I realized that once the user chooses an option, we're done with that column, so rather than making the user go to the next column, we should go to the next column automatically. So I put the code to move to the next column in the "on menuPick" handler, which works fine.

Separately, the user might want to tab *over* the field with the popup menu. That is, they tab to the field with the popup menu, then without dropping it, hit tab again to go to the next column. To get that to work I used the same "EditCell..." code, this time putting it in an "on tabKey" handler of the popup menu button itself, which works fine.

What I'd *really* like is the ability to tab out of the menu *while it's dropped*. I don't think that's possible, because I don't think LiveCode responds to the tab key while a menu is dropped. You don't have any amazing tricks for that one, do you?

Thanks for clearing up "on" vs. "command". That one had been bothering me for a long time.
Last edited by MichaelBluejay on Thu Dec 16, 2010 11:17 pm, edited 1 time in total.

MichaelBluejay
Posts: 235
Joined: Thu Jul 01, 2010 11:50 am

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by MichaelBluejay » Tue Dec 14, 2010 11:01 pm

Can anyone help me with this, or should I contact LiveCode Support?

Zryip TheSlug
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 163
Joined: Tue Jan 26, 2010 10:15 pm
Contact:

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by Zryip TheSlug » Wed Dec 15, 2010 10:38 pm

MichaelBluejay wrote:Can anyone help me with this, or should I contact LiveCode Support?
Hi Michael,

Maybe I misunderstanding something in your need, but actually I'm capable to drop a popup menu, select something in it with the arrow keys or the tab key, hit return for confirming my choice and once the menu closed by the return key, go to the next cell with a tab.

Attached to this reply, a small demo stack.


Best regards,
Attachments
SwitchWithTab.livecode.zip
(8.17 KiB) Downloaded 270 times
TheSlug
http://www.aslugontheroad.com - Tutorials, demo stacks and plugins for LiveCode
Data Grid Helper - An intuitive interface for building LiveCode's Data Grids
Excel Library- Extends the LiveCode language for controlling MS Excel

MichaelBluejay
Posts: 235
Joined: Thu Jul 01, 2010 11:50 am

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by MichaelBluejay » Thu Dec 16, 2010 11:18 pm

Thank you for this. As I said, I was looking for a way to tab out of a popup menu *while it's dropped*. I don't think that's possible, though.

Post Reply