Absent Member.
Absent Member.
1766 views

check items selected in a listbox

Jump to solution

hello.

I need to know how to check if the item in a listbox selected this,

example


move self::listbox1::Items::Count() to wend


perform until wcont = wend

if listbox1::Items[wcont]::Selected = true then

invoke type MessageBox::Show("yes" "")

end-if

add 1 to wcont 

end-perform

thanks

0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

You can get the selected items by using the SelectedItems property which is a collection containing all selected items if you allow for multiple selections or you can just use the property SelectedItem to return a single selected item.

    if listBox1::SelectedItems::Count > 0
       perform varying si as string thru listBox1::SelectedItems
          invoke type MessageBox::Show(si)
       end-perform
    end-if

View solution in original post

0 Likes
5 Replies
Micro Focus Expert
Micro Focus Expert

You can get the selected items by using the SelectedItems property which is a collection containing all selected items if you allow for multiple selections or you can just use the property SelectedItem to return a single selected item.

    if listBox1::SelectedItems::Count > 0
       perform varying si as string thru listBox1::SelectedItems
          invoke type MessageBox::Show(si)
       end-perform
    end-if

View solution in original post

0 Likes
Absent Member.
Absent Member.

thanks, Chris

0 Likes
Vice Admiral
Vice Admiral

Chris

Is it possible to use a ListBoxItem as string? I got an error in my WPF program. I use a variable selItem as type ListBoxItem and selItem::Content as string for the MessageBox parameter

0 Likes
Micro Focus Expert
Micro Focus Expert

Not sure you can do this because the SelectedItems property returns a List of the selected objects which are of their original type and are not of type ListBoxItem. So you either have to iterate thru the collection using an object of the same type or use type object and then cast it to the correct type.

0 Likes
Vice Admiral
Vice Admiral

In my example I add ListBoxItems to the ListBox, but you are right it can be any object. So it's possible to just add a string. It was only a test for me, normally I use WPF binding.

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.