Using the ComboBox
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Using the ComboBox
I have been going round-round looking for code samples on how to use the LC ComboBox with little success. Any links to code sources and/or projects -- much appreciated.
I am now able to put my data selections into the ComboBox and click a choice which changes the label of the ComboBox. But, I would like to implement a script to filter the choices and ensure that the user only types a valid selection from the list OR add a new entry to the list.
Looking for help on:
1) How can I iterate (repeat) through the text list from top-bottom and bottom-top?
2) How can I remove an entry from the list? This is needed to filter the list.
3) How can I determine when the user leaves the ComboBox?
4) When the user leaves the ComboBox, I want to check to be sure the Label is in the list.
If not, I plan to ask the user if this is a "new" entry.
If YES, then how can I add an entry in sorted order to the list?
Thank you for any help.
bill
I am now able to put my data selections into the ComboBox and click a choice which changes the label of the ComboBox. But, I would like to implement a script to filter the choices and ensure that the user only types a valid selection from the list OR add a new entry to the list.
Looking for help on:
1) How can I iterate (repeat) through the text list from top-bottom and bottom-top?
2) How can I remove an entry from the list? This is needed to filter the list.
3) How can I determine when the user leaves the ComboBox?
4) When the user leaves the ComboBox, I want to check to be sure the Label is in the list.
If not, I plan to ask the user if this is a "new" entry.
If YES, then how can I add an entry in sorted order to the list?
Thank you for any help.
bill
Re: Using the ComboBox
Hi Bill,
I don't think there is any special documentation for a "combobox".
Check the dictionary for some useful hints!
1.
2.
3. Since a COMBOBOX is kind of a hybrid button_field, it will receive FIELD messages like
"closefield" (user left the field and did change its content!) and "exitfield" (user left field but did NOT change the content.
4.
Best
Klaus
I don't think there is any special documentation for a "combobox".
Check the dictionary for some useful hints!
1.
Code: Select all
...
put the TEXT of btn "your combo box here" into tList
put the num of lines of tList into tNumOfLines
## TOP to BOTTOM
repeat with i = 1 to tNumOfLines
## do something with -> line i of tList
end repeat
## BOTTOM to TOP
repeat with k = tNumOfLines down to 1
## do your stuff here
end repeat
...
Code: Select all
...
put the TEXT of btn "your combo box here" into tList
## delete line X of tList or whatever
set the text of btn "your combo box here" to tList
...
"closefield" (user left the field and did change its content!) and "exitfield" (user left field but did NOT change the content.
4.
Code: Select all
...
put the TEXT of btn "your combo box here" into tList
put the LABEL of btn "your combo box here" into tEntry
set the wholematches to TRUE
put lineoffset(tEntry,tList) into tFound
if tFound = 0 then
## user entry NOT in list
## ask user...
## Add entry
put CR & tEntry after tList
## Now sort again
sort tList
set the text of btn "your combo box here" to tList
end if
...
Klaus
Re: Using the ComboBox
Klaus
Almost there!!
I got a script to work for "trimming" the list based on the keystrokes entered.
I would like the list to remain open under the text entry area so the user can see the remaining choices.
How can I force a "click" on the drop-down arrow in my script.
FYI: script so far
on keyUp pKey
put the label of button "cbxTitle" into theValue
put length(theValue) into theValueLen
put the text of button "cbxTitle" into tList
put the num of lines of tList into tNumOfLines
--answer the label of button "cbxTitle" & ": :" & theValue & ": :" & theValueLen & ": :" & tNumOfLines
repeat with k = tNumOfLines down to 1
if (theValue <> char 1 to theValueLen of line k of tList) then
--answer "MATCH: " & k & ": :" & theValue & ": :" & line k of tList
delete line k of tList
end if
end repeat
put tList into button "cbxTitle"
set the label of button "cbxTitle" to theValue
end keyUp
Thank you!
bill
Almost there!!
I got a script to work for "trimming" the list based on the keystrokes entered.
I would like the list to remain open under the text entry area so the user can see the remaining choices.
How can I force a "click" on the drop-down arrow in my script.
FYI: script so far
on keyUp pKey
put the label of button "cbxTitle" into theValue
put length(theValue) into theValueLen
put the text of button "cbxTitle" into tList
put the num of lines of tList into tNumOfLines
--answer the label of button "cbxTitle" & ": :" & theValue & ": :" & theValueLen & ": :" & tNumOfLines
repeat with k = tNumOfLines down to 1
if (theValue <> char 1 to theValueLen of line k of tList) then
--answer "MATCH: " & k & ": :" & theValue & ": :" & line k of tList
delete line k of tList
end if
end repeat
put tList into button "cbxTitle"
set the label of button "cbxTitle" to theValue
end keyUp
Thank you!
bill
Re: Using the ComboBox
HI Bill,
You can also use FILTER (less typing ), which is IDEAL for these kind of things:
Best
Klaus
Sorry, I have no idea. Maybe this is not possible at all?westerw wrote:...
I would like the list to remain open under the text entry area so the user can see the remaining choices.
How can I force a "click" on the drop-down arrow in my script.
You can also use FILTER (less typing ), which is IDEAL for these kind of things:
Code: Select all
on keyUp pKey
put the label of button "cbxTitle" into theValue
put the text of button "cbxTitle" into tList
FILTER tList with (theValue & "'")
put tList into button "cbxTitle"
## Does the label really change?
## set the label of button "cbxTitle" to theValue
end keyUp
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 7215
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Using the ComboBox
It's a hack, but try this in the combobox button script:
The button must have the complete list stored as a custom property, which I've named "cText" here. Some keys, like delete, won't trigger unless the list is closed (type Enter to close it.) You could probably experiment with rawKeyDown to fix that.
Code: Select all
on keydown pkey -- set up the filtered content before the list is displayed
put the cText of me into tText -- grab the original list
put the label of me & pkey into tLabel
filter tText with (tLabel & "*")
lock screen
put tText into me
click at (the right of me - 5,item 2 of the loc of me)
focus on me
set the label of me to tLabel
select after me
unlock screen
end keydown
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Using the ComboBox
Klaus wrote:HI Bill,
Sorry, I have no idea. Maybe this is not possible at all?westerw wrote:...
I would like the list to remain open under the text entry area so the user can see the remaining choices.
How can I force a "click" on the drop-down arrow in my script.
You can also use FILTER (less typing ), which is IDEAL for these kind of things:BestCode: Select all
on keyUp pKey put the label of button "cbxTitle" into theValue put the text of button "cbxTitle" into tList FILTER tList with (theValue & "'") put tList into button "cbxTitle" ## Does the label really change? ## set the label of button "cbxTitle" to theValue end keyUp
Klaus
Klaus
I couldn't get the ComboBox to work successfully for what I was trying. So I constructed a Text Entry Field ("txtTitle") with a related Scrolling Field ("lbxTitle") and got the following script to work. Only thing I haven't figured out is how to have LC move its focus from one object to the next "automatically". In Visual Basic, the programmer can set up a "TAB" pattern from one object to the next.
My test stack has three objects: txtTitle, lbxTitle, and Button1
SCRIPT:
local aList
on openField
set the visible of field "lbxTitle" to false
put "" into the field "txtTitle"
end openField
on tabKey
set the visible of field "lbxTitle" to false
put the num of lines of aList into theCount
if (theCount < 1) then
answer "NEW"
end if
focus on button "Button1"
end tabKey
on returnInField
set the visible of field "lbxTitle" to false
put the num of lines of aList into theCount
if (theCount < 1) then
answer "NEW"
end if
focus on button "Button1"
end returnInField
on keyUp pKey
put the field "txtTitle" into theValue
put length(theValue) into theLen
put the txtTitleData of field "lbxTitle" into aList
put the num of lines of aList into theCount
repeat with k = theCount down to 1
if (char 1 to theLen of line k of aList <> theValue) then
delete line k of aList
end if
end repeat
put aList into the field "lbxTitle"
put the num of lines of aList into theCount
set the visible of field "lbxTitle" to true
if (theCount < 1) then
set the visible of field "lbxTitle" to false
else
if (theCount < 10) then
set the height of field "lbxTitle" to 18 * theCount
else
set the height of field "lbxTitle" to 180
end if
end if
set the top of field "lbxTitle" to the bottom of field "txtTitle"
select after text of field "txtTitle"
end keyUp
Thanks for the help.
bill
Re: Using the ComboBox
Found another way to control with keyboard:jacque wrote: ↑Thu Jun 06, 2013 7:02 pmIt's a hack, but try this in the combobox button script:
Code: Select all
on keydown pkey -- set up the filtered content before the list is displayed put the cText of me into tText -- grab the original list put the label of me & pkey into tLabel filter tText with (tLabel & "*") lock screen put tText into me click at (the right of me - 5,item 2 of the loc of me) focus on me set the label of me to tLabel select after me unlock screen end keydown
SET THE MENUMODE OF BUTTON "myCombobox" TO "OPTION"
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
-
- VIP Livecode Opensource Backer
- Posts: 9579
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Using the ComboBox
Westerw.
You are in good hands.
Please place your handlers inside the handler tags (</>).
Craig
You are in good hands.
Please place your handlers inside the handler tags (</>).
Craig
Re: Using the ComboBox
I created a solution some time ago to fix this situation. I can't swear to its elegance, and it doesn't look like a combo box, but it does make a search field with a list of existing values that match.
Code: Select all
####################
/*
Autocomplete text
Two fields: search and results
The search field is an ordinary text field
The results field is a text field with list behavior turned on -->"fldNames"
This will search a list and show the items of that list that start
with the text in the search field.
*/
####################
on keyDown pKey
--this does not include special keys such as return
--enter , or backspace
Lock screen
Put the text of me into ltText
Put pKey after ltText
Put ltText into me
--put the cursor at the end of the entered text
Select after char -1 of me
end keyDown
On keyUp
--filter the list of possible entries based on the
--text of the search field
DoFilter
end keyUp
on openField
--show the search list on clicking into the search field
--provided it is not empty
If the text of me is not empty then
DoFilter
End if
Pass openField
end openField
On closeField
--if the field is empty and the mouse is not inside the key list field
--hide the key list field
--otherwise the user clicked inside the keylist
If the Text of me is empty \
AND the mouseLoc is not within the rect of fld "fldNames" then
Hide fld "fldNames"
--clear all fields and diable the "Clear" button
ClearRecord
disable btn "btnClear"
End if
if the mouseLoc is not within the rect of fld "fldNames" then
Hide fld "fldNames"
End if
--passing the Close field message allows the default text behavior to work.
Pass closeField
end closeField
On exitField
--if the field is empty and the mouse is not inside the key list field
--hide the key list field
--otherwise the user clicked inside the keylist
If the text of me is empty \
AND the mouseLoc is not within the rect of fld "fldNames" then
Hide fld "fldNames"
ClearRecord
End if
if the mouseLoc is not within the rect of fld "fldNames" then
Hide fld "fldNames"
End if
Pass exitField
end exitField
on rawKeyUp pKey
--on backspace
--this updates the results as the text changes
if pKey is 65288 then
DoFilter
End if
Pass rawKeyUp
end rawKeyUp
On DoFilter
###############################
/*
get and filter the names of active clergy members
*/
##############################
Local ltPreList
Local tSQL
Local ltList
Local ltFilter
Lock screen
--this will prevent the possible entries from being edited on accident
--build SELECT query for the auto complete
[complete list of entries]
###################
/*
i got the data from a sqlite database but a custom
property with the entire list would work just as well.
*/
###################
--parse the information in prelist
--item del is tab for returned info
--sort the list
sort lines of ltList ascending by item 1 of each
Put the uText of fld "fldSearchName" & "*" into ltFilter --uText
--filter the list
Filter ltList with ltFilter
--load the fldNames box
Put ltList into fld "fldNames"
Show fld "fldNames"
--put the cursor at the end of the entered text
Select after char -1 of me
--keep the fldNames box fitting the text
--maximum height of the fldNames box is 130
If the formattedheight of fld "fldNames" < 130 then
Set the height of fld "fldNames" to the formattedHeight of fld "fldNames"
Set the vScrollBar of fld "fldNames" to false
Else
Set the height of fld "fldNames" to 130
Set the vScrollBar of fld "fldNames" to true
End if
--make sure the fldNames box still aligns correctly
set the top of fld "fldNames" to the bottom of me +1
Set the left of fld "fldNames" to the left of me
end DoFilter
--in the list display field script --"fldNames" as referenced in the code above
on mouseUp
--put the clicked line into the search field
--then hide the search results box
select the selectedLine
set the uText of fld "fldSearchName" to the selectedText
<do stuff>
put empty into me
Hide me
end MouseUp