Ask Your Question

Solved: listbox selection set to match a text string [closed]

asked 2018-04-17 04:41:31 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

I am trying to select a listbox entry so that it matches an array value. This is in a search routine so that if the text in TextBox1 matches the search criterion [in this case, SearchArray(zzz, 4)], then the selected value, in text, not index number, of ListBox1 matches the string value of SearchArray(zzz, 5).

If oDialog1.getControl("TextBoxx1").Text = SearchArray(zzz, 4) Then

oDialog1.getControl("ListBox1").?????? = SearchArray(zzz, 5)

End If

What might replace the question marks?

Thanks in Advance.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by erAck
close date 2018-04-18 12:26:00.716559


@hvankampen: In the future, please do not post as community wiki. Also, if my answer does not work, then please provide a few more details about the code and a complete example. See guidelines for asking.

Jim K gravatar imageJim K ( 2018-04-17 15:47:10 +0200 )edit

2 Answers

Sort by » oldest newest most voted

answered 2018-04-17 15:53:51 +0200

Jim K gravatar image

updated 2018-04-17 16:02:21 +0200

XListBox.selectItem() should do the trick. Based on the code snippet in the question, try this:

oDialog1.getControl("ListBox1").selectItem(SearchArray(zzz, 5))

For a more robust solution, here is some code in Python which you can adapt for Basic.

if listCtrl.supportsService(""):
    if selectedValue and selectedValue in values:
        listCtrl.selectItem(selectedValue, True)
        listCtrl.selectItemPos(0, True)
elif listCtrl.supportsService(""):
    if selectedValue and selectedValue in values:
edit flag offensive delete link more

answered 2018-04-18 03:58:10 +0200

hvankampen gravatar image

Thank you for your help. I thought it had to be something like this. The trouble was actually being caused by another part of the code. The final result was:

oDialog1.getControl("ListBox1").selectItem(SearchArray(zzz, 5), true)

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2018-04-17 04:41:31 +0200

Seen: 135 times

Last updated: Apr 18 '18