Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
Choose Language Hide Translation Bar
Highlighted
MathStatChem
Level VI

How to get reference to selected display object?

If I use the selection tool to manually select a display object in a report or journal window, how do I get a reference to that selected item?  

 

What I would really like to do is to have an add-in that copies the selected item as an image and puts that image into a journal.  

2 REPLIES 2
Highlighted
Craige_Hales
Staff (Retired)

Re: How to get reference to selected display object?

It doesn't look like there is a way to directly ask a displaybox if the selection attribute set. Which is odd, because you can set it and clear it. @XanGregg @audrey_shull 

It does look like XPATH can tell, at least sometimes. This is my first venture into XPATH, so I'm probably missing something obvious. Run lines two and three after selecting aaa or bbb with the selection tool.

x=newwindow("x",hb=hlistbox(textbox("aaa"),textbox("bbb")));
show(hb<<getxml);
(hb<<xpath("//*[@selected='true']"))<<gettext;

if I select just aaa, or just bbb, it reports the correct box. If I select both, I get nothing. Maybe an XPATH expert can point the way. @davidbarbour 

 

hb << getxml = "<ListBox width=\!"69\!" height=\!"27\!">
<TextBox width=\!"32\!" height=\!"27\!">aaa</TextBox>
<TextBox leftOffset=\!"32\!" topOffset=\!"0\!" width=\!"37\!" height=\!"27\!" selected=\!"true\!">bbb</TextBox>
</ListBox>";

Craige
Highlighted
Craige_Hales
Staff (Retired)

Re: How to get reference to selected display object?

Found it. Move up higher in the display box tree, probably to the root. For example

((hb<<parent)<<xpath("//*[@selected='true']"))<<classname;

Apparently the individually selected items propagate up to the containing node.

 

(hb << parent) << getxml = "<ListBox width=\!"64\!" height=\!"26\!" selected=\!"true\!">
<ListBox width=\!"64\!" height=\!"26\!">
<TextBox width=\!"30\!" height=\!"26\!">aaa</TextBox>
<TextBox leftOffset=\!"30\!" topOffset=\!"0\!" width=\!"34\!" height=\!"26\!">bbb</TextBox>
</ListBox>
</ListBox>";

Since A and B were selected, which are all the children of the hlistbox, It became selected, but it is also all of the children of another listbox, which became selected. Probably need to try a few more examples to be sure.

Craige
Article Labels

    There are no labels assigned to this post.