[Closed] Function run upon Button Pressed
The code below is a simple example file i put together for the sake of finding a solution.
I want the list of names to be updated upon the user clicking Apply or hitting Enter on the keyboard. Ideally it would run the fnPopulateList to repopulate the list of names. Is there a way to do that?
try(destroyDialog ::rlRenaming)catch()
rollout rlRenaming "Renaming"
(
global names = #("A","B","C","D")
global index = 0
multiListbox mlName "Names:" width:200 height:6 pos:[10,10]
fn fnPopulateList = (mlName.items = names)
fn fnEditName = (
try(destroyDialog ::rlEditField)catch()
rollout rlEditField ("Name Editor")
(
label lbValue "Name:" pos:[15,15]
editText etNewName "" width:75 pos:[50,13]
button btnSubmit "Apply" width:115 height:30 pos:[15,40]
fn fnApplyChanges = (
names[index] = etNewName.text
try(destroyDialog ::rlEditField)catch()
-- run function to repopulate list from the global names array!!
)
on etNewName entered txt do fnApplyChanges()
on btnSubmit pressed do fnApplyChanges()
on rlEditField open do
(
etNewName.text = names[index]
setfocus etNewName
)
)
createDialog rlEditField 150 80 style:#(#style_SysMenu, #style_ToolWindow)
)
on mlName doubleClicked itm do (
index = itm
fnEditName()
)
on rlRenaming open do
(
fnPopulateList()
)
)
createDialog rlRenaming 220 120 style:#(#style_SysMenu, #style_ToolWindow)
try(destroyDialog ::rlRenaming)catch()
rollout rlRenaming "Renaming"
(
local names = #("A","B","C","D")
local index = 1
multiListbox mlName "Names:" width:200 height:6 pos:[10,10]
fn updateList text:"" index: =
(
if index != unsupplied do names[index] = text
mlName.items = names
)
rollout editFiled "Name Editor"
(
label lbValue "Name:" pos:[15,15]
editText etNewName "" text:names[index] width:75 pos:[50,13]
button btnSubmit "Apply" width:115 height:30 pos:[15,40]
fn applyChanges =
(
updateList text:etNewName.text index:index
destroyDialog editFiled
)
on etNewName entered txt do applyChanges()
on btnSubmit pressed do applyChanges()
on editFiled open do setfocus etNewName
)
fn fnEditName i =
(
index = i
createDialog editFiled 150 80 style:#(#style_SysMenu, #style_ToolWindow) modal:on
)
on mlName doubleClicked index do fnEditName index
on rlRenaming open do updateList()
)
createDialog rlRenaming 220 120 style:#(#style_SysMenu, #style_ToolWindow)
everything is much easier. you can do it in local scope
Nicely done. I was hoping there was an easier way to do that. I had tried a few different ideas and they were becoming a pain in the ass for sure. So It’s nice to know that something this easier can be done.
Thank you Denis.
I did that for an add to SME toolbar I created. Here is how I did it for a dotnetcontrol:
dotNetControl smeAdd_cb "System.Windows.Forms.ComboBox" pos:[5,5] width:(SME_AddObjMats.width-55) height:20 across:2
fn views_smeAdd =
(
-- Collect the view Names into an array
smeAdd_views = for val in 1 to sme.getNumViews() collect (sme.getView val).name
-- Clear the ComboBox list
smeAdd_cb.items.clear()
-- Build a new ComboBox list using the view array
smeAdd_cb.items.addrange smeAdd_views
)
-- When you expand the ComboBox rebuild the ComboBox list
on smeAdd_cb DropDown do
(
-- Run views_smeAdd function to rebuild the ComboBox to match the current SME views
views_smeAdd()
)
So the first is the function to build the name list, the second is a simple use.
-Eric
Very cool.
Thanks for sharing that. It’s like you know me to well. I’m sure I would have asked this at some point haha.