Highlighted
Absent Member.
Absent Member.
2140 views

Find Objects in combobox WPF

Jump to solution

I have a combobox filled with a list of objects itemAttributes that is defined as 

01 value-id pic 99999999 value 0 property as "ID".
01 attribute-value pic x(30) value spaces property as "VALUE".

im triying to find the index of the object inside the combobox by its ID property but i cant manage to figure it out.

something like this

set cbAttrib1::SelectedIndex to cbAttrib1::Items::IndexOf(valueID)

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Find Objects in combobox WPF

Jump to solution

Is this what you are looking for?

This example displays the VALUE property in the list and then allows you to set the selected item to the one that matched the ID property given.

       01 entry1 type findentry.myitems value new findentry.myitems(property ID = 3, property VALUE = "TEST1").
       01 entry2 type findentry.myitems value new findentry.myitems(property ID = 2, property VALUE = "TEST2").
       01 entry3 type findentry.myitems value new findentry.myitems(property ID = 1, property VALUE = "TEST3").
       01 mylist type ObservableCollection[Type findentry.myitems].
     
           
           set mylist to new ObservableCollection[type findentry.myitems]
           invoke mylist::Add(entry1)
           invoke mylist::Add(entry2)
           invoke mylist::Add(entry3)
           
           set Combobox1::ItemsSource to mylist
           set Combobox1::DisplayMemberPath to "VALUE"
           set Combobox1::SelectedValuePath to "ID"
           
           set Combobox1::SelectedValue to 1

       end method.
       end class.
       class-id findentry.myitems.
       working-storage section.
       01 valueid        pic 99999999 value 0 property as "ID".
       01 attributevalue pic x(30) value spaces property as "VALUE".

       end class.

View solution in original post

0 Likes
4 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Find Objects in combobox WPF

Jump to solution

Can you please clarify what it is exactly that is in the Items collection? You have a class defined with the two properties shown above and you are adding instances of that class to the combobox?

Can you show me an example of how you are loading the combobox?

Thanks.

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Find Objects in combobox WPF

Jump to solution

Yes, is class with 2 properties.

set lblAttrib1::Content to category-attributes(idx)::NAME

set cbAttrib1::ItemsSource to category-attributes(idx)::VALUES

set cbAttrib1::DisplayMemberPath to "VALUE"

set cbAttrib1::SelectedValuePath to "ID"

i want to find a specidic attribute in the combox and then set the selected value to that index.

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Find Objects in combobox WPF

Jump to solution

Is this what you are looking for?

This example displays the VALUE property in the list and then allows you to set the selected item to the one that matched the ID property given.

       01 entry1 type findentry.myitems value new findentry.myitems(property ID = 3, property VALUE = "TEST1").
       01 entry2 type findentry.myitems value new findentry.myitems(property ID = 2, property VALUE = "TEST2").
       01 entry3 type findentry.myitems value new findentry.myitems(property ID = 1, property VALUE = "TEST3").
       01 mylist type ObservableCollection[Type findentry.myitems].
     
           
           set mylist to new ObservableCollection[type findentry.myitems]
           invoke mylist::Add(entry1)
           invoke mylist::Add(entry2)
           invoke mylist::Add(entry3)
           
           set Combobox1::ItemsSource to mylist
           set Combobox1::DisplayMemberPath to "VALUE"
           set Combobox1::SelectedValuePath to "ID"
           
           set Combobox1::SelectedValue to 1

       end method.
       end class.
       class-id findentry.myitems.
       working-storage section.
       01 valueid        pic 99999999 value 0 property as "ID".
       01 attributevalue pic x(30) value spaces property as "VALUE".

       end class.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Find Objects in combobox WPF

Jump to solution

basically im looking how to do

ComboBox.FindString(String) Returns the index of the first item in the ComboBox that starts with the specified string.

But I think it will be better if I use Combobox::SelectedVaue as Sugested, Just gotta change the logic in my code.

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.