Using Option Menu as ComboBox

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
westerw
Posts: 14
Joined: Tue Apr 09, 2013 7:33 pm

Using Option Menu as ComboBox

Post by westerw » Mon Jun 03, 2013 8:09 pm

Coming from Visual Basic, I could use a comboBox easily. The VB comboBox has methods when entering/leaving a comboBox, filtering down the comboBox as the user types, etc.

I am having trouble emulating the same approach with the Option Menu. I have placed an Option Menu on my form with the "combobox" look and feel. I load the data into the dgText from a CSV file and have set the "label" as blank. Code follows.
-- FILL OptionMenu with data (VB ComboBox)
answer file "Please choose the Title file to import" with type "Comma Separated Values|csv|CSV"
if the result is not "cancel" then
-- save the FilePathName
put it into tFileName
-- get the contents of the CSV file
put URL ("file:" & tFileName) into tFileContents
-- display the file contents in the data grid
replace comma with tab in tFileContents
put tFileContents into dgText of button "cbxTitle"
end if


This is what I would like to do:
1) When the user clicks a row in a DataGrid, take one of the fields and place it into the comboBox "text" box. If the user changes the contents, they would select from the comboBox drop list. It seems that when I put the field into the button, the drop list disappears and only has the one entry. Code follows. The comboBox is "cbxTitle".
-- MOVE data for BaseRec to fields
put theBaseType into field "txtBaseType"
put theKCNumber into field "txtKCNumber"
put tDataRow["First Name"] into field "txtFirstName"
put tDataRow["Last Name"] into field "txtLastName"
put tDatarow["Related Link"] into field "txtRelatedLink"
put tDataRow["Title"] into button "cbxTitle"

2) I would like to emulate the VB methodology of filtering down the list as the user types. Using the list below, if the user enters an "M" --> filter down to the 7 "M" entries. Then when the "Mr" appears -- filter down to the 2 "Mr" entries. When the user switches to a different row in the data grid, the comboBox list must go back to its original size.
GK
Hon.
LCDR
LTC
Maj.
Mr.
Mrs.
Ms.
MSGT
PGK

Seems like it should be easy, but I am struggling.
Any help appreciated.
thanks, bill
PSD

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Using Option Menu as ComboBox

Post by Mark » Tue Jun 04, 2013 12:35 pm

Hi Bill,

Search List Lib might be useful for you. Enter text in a field and watch all relevant items in your list appear in a menu. The result is similar to a combobox, but it shows relevant items only and handles keystrokes such as tab, escape and return better.

Image

You need to make a donation to access the private section of the website.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Using Option Menu as ComboBox

Post by FourthWorld » Tue Jun 04, 2013 6:36 pm

westerw wrote:Coming from Visual Basic, I could use a comboBox easily. The VB comboBox has methods when entering/leaving a comboBox, filtering down the comboBox as the user types, etc.

I am having trouble emulating the same approach with the Option Menu.
Have you tried LC's native comboBox control?

It responds to keyDown events, so you should be able to do the filtering you need.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Using Option Menu as ComboBox

Post by Mark » Tue Jun 04, 2013 6:44 pm

Hi,

I think I should point out that, while it is possible to write all the scripts to do all necessary filtering with a normal combobox by yourself, a normal combobox will never provide the same flexibility and responsiveness as the library I recommended in my previous post, because the "native" combobox isn't really a native control but rather a mockup that doesn't respond very well to the tab key, arrowkeys and the mouse.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Using Option Menu as ComboBox

Post by FourthWorld » Tue Jun 04, 2013 6:59 pm

True, using the built-in control may require more scripting if your custom control happens to already be scripted to do exactly what he needs.

But on the flipside, the built-in control is already set up for multi-platform native appearances, and doesn't have a scrollbar when displaying a non-scrolling list.

Scripting is so easy in LiveCode that there are always multiple solutions to just about anything. I trust the user will adopt whatever works best for his specific needs.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Using Option Menu as ComboBox

Post by Mark » Tue Jun 04, 2013 7:16 pm

Richard,

I don't think that the combobox's "native appearance" is a success in LiveCode, but I guess that's a matter of taste. If you really think that LiveCode's combobox looks better, I'd call that a small sacrifice for all the features you get with my search list lib. That's hardly a "flipside". Why do you think that my search list lib has a scroll bar if it doesn't need one?

I agree that scripting is easy, but sometimes having a ready-made custom control is even easier. I don't think you do OP a favour by suggesting to make a solution by himself, although it could be a nice exercise.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Using Option Menu as ComboBox

Post by FourthWorld » Tue Jun 04, 2013 7:36 pm

The OP has experience in VB, so it seems safe to assume he's a competent scripter. I'm sure your solution is nice, and no doubt there are others that are also nice, but sooner or later anything in LC requires some scripting, and sometimes it's easier to use prefab code and other times it's easier to use code you're familiar with.

Please note that I never dissuaded him from evaluating your custom control, or any other solution he may come across. But his post didn't mention whether he was aware that LC included a native combobox, and it seemed helpful to let him know it's there.

If he's used VB he probably knows what he's doing. No matter what he chooses, I trust his judgment.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Using Option Menu as ComboBox

Post by Mark » Tue Jun 04, 2013 7:51 pm

Richard,

I never doubted OP. I would think that he already looked at what's available in LiveCode, but of course I can't really know that.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Using Option Menu as ComboBox

Post by Mark » Tue Jun 04, 2013 7:55 pm

Hi Bill,

In addition to my previous message about Search List Lib, I should tell you that the field can be included in a datagrid and it should just work. I know that filtering and displaying the contents of a combobox can be extremely cumbersome and even more so in a datagrid. Search List Lib doesn't have these problems. If you encounter any problems, you can let me know.

kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

westerw
Posts: 14
Joined: Tue Apr 09, 2013 7:33 pm

Re: Using Option Menu as ComboBox

Post by westerw » Wed Jun 05, 2013 2:27 pm

FourthWorld wrote:
westerw wrote:Coming from Visual Basic, I could use a comboBox easily. The VB comboBox has methods when entering/leaving a comboBox, filtering down the comboBox as the user types, etc.

I am having trouble emulating the same approach with the Option Menu.
Have you tried LC's native comboBox control?

It responds to keyDown events, so you should be able to do the filtering you need.

your answer makes TOO much sense. BUT, where do I find LC native comboBox control??
I checked the dictionary -- nothing! I checked under object -- nothing listed!
The only place I find the comboBox is as a version of the option menu.

After loading from a CSV file, the Custom Property (dgData) shows my list of data in the Property Contents but not in the Text of the option menu.
I have tried "set" and "put" to move the dgData to Text, but these cause either a compile time or run-time error.
What I want to do is make sure that the Text part of the option menu shows all the options for the user when I set or put a value into the Label.
I am really struggling to find the correct way to use the set/put statements. It all seems much easier in Visual Basic.

I think once I can get this initialization working each time the user clicks on a DataGrid and I populate fields and labels of comboBox(es),
I can figure out the script to filter down the entries.

Thank you
bill

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Using Option Menu as ComboBox

Post by Mark » Wed Jun 05, 2013 2:36 pm

Hi Bill,

Perhaps you're looking in the wrong place in the dictionary. Make sure that "All" is selected in the left column and type "comboBox" in the search field. The word comboBox should now appear in the second column and you can click on it.

The comboBox control is in the tools palette, left to the pop-up menu and above the progress bar.

What exactly do you mean with "the Text part of the option menu"? Do you mean the menu or the label? A big problem of the combobox is that you can't open the menu by typing in the field of the comboBox and when the menu is open, you can't type in it. Hence the solution I proposed earlier.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

westerw
Posts: 14
Joined: Tue Apr 09, 2013 7:33 pm

Re: Using Option Menu as ComboBox

Post by westerw » Wed Jun 05, 2013 6:15 pm

Mark

OK -- found the comboBox button (really obvious -- don't know how I missed it).
I use this code to get the data from a CSV file for the custom property of the comboBox

-- FILL ComboBox with data
answer file "Please choose the Title file to import" with type "Comma Separated Values|csv|CSV"
if the result is not "cancel" then
-- save the FilePathName
put it into tFileName
-- get the contents of the CSV file
put URL ("file:" & tFileName) into tFileContents
-- file the custom property of the combobox
replace comma with tab in tFileContents
set the dgTitle of button "cbxTitle" to tFileContents
end if

What it does:
1) puts the tFileContents into the Property Contents for "customKeys"
2) puts the literal "dgTitle" into the Custom Properties associated with "customKeys"
3) puts "nothing" into the Menu Items of the Basic Properties

What I expected (would like):
1) put the tFileContents into the Custom Properties of either "customKeys" or a new "dgTitle"
2) put the tFileContents into the Menu Items list

Thanks, bill

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Using Option Menu as ComboBox

Post by Klaus » Wed Jun 05, 2013 6:34 pm

Hi Bill,

all the "DGxyz..." properties will ONLY do something when you set a DATAGRID to them.
Example:
...
set the DGtext of grp "datagrid 666" to Var_With_Tab_Text
...
Will populate a datagrid of type TABLE with content.

All other objects will only have a new custom property after that, but nothing else will happen, as you have experienced!

Hint:
ALWAYS use THE when dealing with custom properties: answer THE xyz of btn "whatever"


Best

Klaus

Post Reply