Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Return value from list box without the use of a button
#1
Hello,

I have been using QM2 for a little over a year now and have just recently begun to transition over to QM3. I have little developer experience but usually can figure things out by reading through the QM2 forums.

I am working on transferring a macro I have in QM2 to QM3 and am struggling to figure out how to return a value from a Listbox item when it is selected without the use of a "return" button. 

Here is the completed script in QM2
Code:
Copy      Help
int w=win("" "Afx:*" "" 0x4)
Acc a.Find(w "PAGETAB" "" "class=SysTabControl32[]id=1509" 0x1030)

 
ARRAY(Acc) c; int i
a.GetChildObjects(c 0 "" "" "" 16)

for i 0 c.len
c[i].Role(_s); out _s
out c[i].Name
str j = c[i].Name
ARRAY(str) b ;; Arrary for to populate listbox names
b[] = c[i].Name 
out b[0]

rep 100
str s=b
int m=(ListDialog(s "v1.0" "TabJumper"0x1 0 01 01)); if(i=0) ret
str p = b[m-1]
out p



Acc a1.Find(w "PAGETAB" F"*{p}*" "class=SysTabControl32" 0x1035); err mes- "Can't Find Layer"

act w
act a
int d = child(a)
SendMessage d LVM_ENSUREVISIBLE a.elem-1 0 ;; scroll to the location to make sure it's visible
a1.Select(3)

The line that gives me the value when the list item is selected is 
Code:
Copy      Help
str s=b

int m=(ListDialog(s "v1.0" "TabJumper"0x1 0 01 01)); if(i=0) ret
str p = b[m-1]
out p

So in my QM3 version, I am trying to accomplish the same thing. But so far I can only figure out how to return the value of what item is selected in the Listbox when I press ok. Can anyone give some advice on how this could be done? 
 
Code:
Copy      Help
 
//.
using Au;
using Au.Types;
using System.Windows;
using System.Windows.Controls;
script.setup(trayIcon: true);
//..





{  
var w = wnd.find(1, "**m Master View||?Layer:*" , "Afx:*");

elm[] LayerTabs = (w.Elm["PAGETAB", prop: "id=1509"].FindAll());


print.it(LayerTabs);
print.it(LayerTabs.Length);

var j = LayerTabs.Length;
string [] LayerNames = new string [j];
print.it(LayerNames.Length);

for (int i = 0; i < j; i++) {  
LayerNames[i] = LayerTabs[i].Name;
print.it(i);
print.it(j);
print.it(LayerNames);

}


var b = new wpfBuilder("Tab Jumper v1").WinSize(300) //create Window object with Grid control; set window width 400
//.R.Add("Layer Search", out TextBox text1).Focus() //add label and text box control in first row
//.R.Add("Page", out ComboBox combo1).Items("Matrix|Signals") //in second row add label and combo box control with items
.R.AddSeparator()
.R.Add(out ListBox listbox1).Items(LayerNames).Height(700) // add listbox item adding items from "LayersTab" Aaray 
.R.AddSeparator()
.R.Add( "", out TextBlock block1)
.R.AddSeparator()
.R.AddOkCancel() //finally add standard OK and Cancel buttons
.End();

block1.Text =
"Select a Layer to Jump to that layer ";
block1.TextWrapping = TextWrapping.Wrap;
//b.End();
b.ShowDialog();//show the dialog and wait until closed; return if closed not with OK button


var Select = listbox1.SelectedItem;

var e = w.Elm["PAGETAB", $"{Select}", "id=1509", EFFlags.HiddenToo].Find(1); /*image:WkJNGyEEAAT+vz/zdHndFpCV6tVSp9qZJ7eLLtt4/GNBy7GKhqKxcEACFv/jpva5LRbBAHpGrUmTOk9kLtAMAsIg5uXqw8dY0yA0u8OqSfav0Jq2NMtqDLZZ9+3/HscxRVHw+XxIkoSqqsiyjPF4TFmW5HlOmqY8Kw5/HPY4THEQDquRc4RfxvnocjkR8eBljdYcSnPM5F8ux9xl5ikKypoYMywbtVHmpjWdsAbr7oglQUCQVtKVkB1VJvQt3PZgYJzI9jGtVgy6EqhrkUZ77MEtVoyuhBheCXegMYzwWfgNhL9mopzfMPEPAQ==*/
print.it(e);
e.Invoke();
}
#2
Insert before the ShowDialog line:

C# code:
listbox1.SelectionChanged+=(_,e)=> {
    var s = listbox1.SelectedItem as string;
    print.it("SelectionChanged", s, listbox1.SelectedIndex);
};
#3
Gintaras,

Thanks for your help! This worked!


Forum Jump:


Users browsing this thread: 1 Guest(s)