We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question
0

How to pre-select ListBox items in a dynamic dialog? [closed]

asked 2020-06-15 15:43:56 +0200

updated 2021-05-20 19:01:24 +0200

Alex Kemp gravatar image

I have not managed to pre-select ListBox items in a dynamically built dialog. While I can check it operates properly using a "static" dialog.

selectItem(…) or selectItemPos(…) seem to behave differently

Am I doing something wrong?

C:\fakepath\ListBoxControl.odt

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2021-05-20 19:01:33.139327

Comments

selectItem(…) or selectItemPos(…) seem to behave differently

In what way do they seem to behave differently?

Jim K gravatar imageJim K ( 2020-06-15 20:04:17 +0200 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2020-06-15 20:03:53 +0200

Jim K gravatar image

updated 2020-06-16 20:01:32 +0200

Display the dialog first. Items cannot be selected until the dialog is fully created.

Dim oListCtrl As Object
oListCtrl = _addListBox( Array(COL1,ROW2,WIDTH1,70), default, values, MultiSelect)
DlgControl.setVisible(True) ' show dialog'
oListCtrl.selectItemPos(1, True)
oListCtrl.selectItem("Milan", True)
DlgControl.execute()
edit flag offensive delete link more

Comments

@Jim K

Believe this is all that is needed between setVisible & execute:

Dim oListCtrl As Object
oListCtrl = DlgControl.getControl("ListBox")
oListCtrl.selectItemPos(1, True)
oListCtrl.selectItem("Milan", True)

Had problem with each of the lines with oListCtrl using your code. (Not the Dim statement)

First line got invalid use of object. Other two have extra space before period.

Ratslinger gravatar imageRatslinger ( 2020-06-16 03:50:36 +0200 )edit

@Ratslinger: Fixed the spaces. As for the error you encountered, the answer doesn't show it, but I modified _addListBox to be a function that returns the list control. That way, it only has to be obtained in one place in the code, keeping things neat and tidy.

Jim K gravatar imageJim K ( 2020-06-16 20:10:17 +0200 )edit

@Jim K,

Thank you. Knew there must be a reason but did not see based upon existing code.

Ratslinger gravatar imageRatslinger ( 2020-06-16 20:16:15 +0200 )edit

Question Tools

1 follower

Stats

Asked: 2020-06-15 15:43:56 +0200

Seen: 96 times

Last updated: Jun 16 '20