| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Re: Re: using dynamic_list_control class
Zurab,
What you need to do is create an empty object when the dialog is loaded
and then append to that object onpush(). For example,
**************************d1.dlg****************************
/*
*! VERSION 1.0.0 15mar2007
*/
VERSION 9
SYNCHRONOUS_ONLY
POSITION . . 400 300
OK ok1, label("OK")
CANCEL can1, label("Cancel")
SUBMIT sub1, label("Submit")
RESET res1
SCRIPT POSTINIT
BEGIN
program setup
END
DIALOG main, label("Test EDIT control as varlist")
BEGIN
TEXT tx_var 10 10 100 ., ///
label("Variable:") right
EDIT ed_var +105 @ 100 .,
BUTTON bu_add @ 50 100 ., ///
label("Add Variable") onpush(program getVar)
TEXT tx_vlist 10 90 100 ., ///
label("Variable list:") right
LISTBOX lb_vlist +105 @ 100 ., ///
contents(variables)
END
LIST variables
BEGIN
// intentionally empty
// this list will be populated by d1_work.ado
END
PROGRAM setup
BEGIN
put "d1_work Init"
stata hidden
END
PROGRAM getVar
BEGIN
put "d1_work addVar " main.ed_var
stata hidden
END
*********************************************************
******************d1_work.ado*****************************
program d1_work
version 9
gettoken subcmd 0 : 0
`subcmd' `0'
end
program Init
.dlist = .dynamic_list_control.new , ///
dialogname(d1) controlname(main.lb_vlist)
end
program addVar
syntax [anything]
.dlist.appendItem, item("`anything'")
end
*********************************************************
Kevin
Zurab Sajaia wrote:
Thanks a lot Sergiy,
It's not quite what I meant, perhaps I should have been clearer in my
question:
Lets consider this setup, there is an editbox, button and a listbox,
user adds items to the list by typing into the editbox and then
pushing the button. So if we link a code similar to yours to the
-onpush- event of the button then everytime we push the button
".dlist=.dynamic_list_control.new, dialogname(mydlg2)
controlname(tabby2.lb1)" line will clear the list ...
I "fixed" the problem by rewriting my own apenditem / removeitem
programs (mostly taken from dynamic_list_control.class) but posted the
question to make sure there is no easier way to use already existing
tool.
best,
zurab
----- Original Message ----- From: "Sergiy Radyakin"
<[email protected]>
To: <[email protected]>
Sent: Thursday, March 15, 2007 3:53 PM
Subject: st: Re: using dynamic_list_control class
Hello Zurab,
I am using the file dynamic_list_control.class from Stata's base ADO
directory as a hint on your question.
Notice comments
// WE MUST KEEP THE GUI CONTROL AND THE CLASS SYSTEM IN SYNC
throughout.
So if I wanted to add an item to a dynamic list I do it like this:
.dlist=.dynamic_list_control.new, dialogname(mydlg2)
controlname(tabby2.lb1)
.dlist.setList, newlist(`"`vars'"')
.dlist.print
.mydlg2_dlg.Vars1.Arrpush "Something"
.mydlg2_dlg.tabby2.lb1.additem "Something"
.`.dlist.fullListReference'.Arrpush "Something2"
.`.dlist.fullObjectReference'.additem "Something2"
classutil drop .dlist
Notice that Vars1 is defined as a dummy list in the dialog file.
You can either address the list directly (as in "Something"), or
refer to it's fields, containing the full references (as in
"Something2").
.dlist.print will display the contents of these fields.
In short, the above code will create a dynamic list object with items
from local macro vars, and then append two items to the end of the list.
Question to all dialog programmers. What references/tutorials on
dialog programming and controls are available in the Internet? Google
search yields hardly a handfull of links :(
Best Regards, Sergiy Radyakin
----- Original Message ----- From: "Zurab Sajaia" <[email protected]>
To: "statalist" <[email protected]>
Sent: Thursday, March 15, 2007 5:35 PM
Subject: st: using dynamic_list_control class
Dear all,
I'm building a dialog with dynamically changed content and based on
earlier discussions on the Statalist came to use
dynamic_list_control class.
James Hassell kindly showed how to set the list interactively, and
now I'm trying to use other methods of the class, namely appending
or deleting an item.
My problem is that whenever the new instant is created and linked to
the listbox, contents of the list are cleared:
dlist = .dynamic_list_control.new , dialogname(d1)
controlname(main.lb_level)
.set method (which is called by .new) has "._clearList" at the end
that clears the list. This was not an issue in the example given by
James because he was then redefining the new list by:
.dlist.setList, newlist(`levels')
but if I need to add (or drop) one item only this seems to be a
problem:
.dlist.appendItem, item("something") will result in list containing
just "something".
I'd appreciate much any advice what to change (if Im doing something
wrong)
Thanks,
Zurab
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/