Highlighted
Super Contributor.
Super Contributor.
75 views

Get Selected Items from ListBox WinForm

Jump to solution

I would like to get the items that the user has selected from a Lis tBox. I tried the following:

move ListBox::SelectedItem::ToString to STR-ITEM

This code works well if the 'SelectionMode" property of the ListBox is set to 'One' but this however, constrains the user to only pick one item from the List Box. I have set the  'SelectionMode" property of the ListBox  to 'MultiSimple' in order to allow the user to pick more than one item. But setting this property sems to only return the first item selected when I use the code above. I tried retrieving  the index using the following code:

move lst-GROUP-PROFL-TBL::SelectedIndex to THE-IDX-2.

But this too returns only the first item that is selected in the list. What I basically need is to retrieve all the items that the user has selected in a list box either by their string text or by their index and then store them in a table. For example, if the user chooses items 'January' 'February' and "March"  from a list box, I would like to store those items in a table. Storing the items in a table is fairly easy but I am stuck as I cannot seemed to get all the items that the user has selected from a List Box.

 

 

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

You need to use the SelectedItems collection instead of SelectedItem.

 

Something like this:

       01 table-num string occurs 5 times.
       
           declare sub1 as binary-long = 1
           perform varying selecteditem as string thru listBox1::SelectedItems
               move selecteditem to table-num(sub1)
               add 1 to sub1
           end-perform

View solution in original post

0 Likes
2 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

You need to use the SelectedItems collection instead of SelectedItem.

 

Something like this:

       01 table-num string occurs 5 times.
       
           declare sub1 as binary-long = 1
           perform varying selecteditem as string thru listBox1::SelectedItems
               move selecteditem to table-num(sub1)
               add 1 to sub1
           end-perform

View solution in original post

0 Likes
Highlighted
Super Contributor.
Super Contributor.
This worked! Thank you.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.