larolsen
14 years agoContributor
Problem with getting items from WPF combobox
Hi
I am trying to make testscripts for a WPF application. I would like to make a helper function, that receives a combobox object, and a text. If the text exists in the combobox items, it should select it. If the text does not exist it should return a False flag.
The text in the combobox is stored in a TextBlock object within the Combobox hierarchy, and the TextBlock has a property called "Text"
This is the code have so far:
Dim MyString
Dim L_astrPropNames1
Dim L_astrValueNames1
ReDim L_astrPropNames1(0)
L_astrPropNames1(0) = "Text"
ReDim L_astrPropValues1(0)
L_astrPropValues1(0) = "1800-3200 Hz"
MyString = mycombobox.FindAllChildren(L_astrPropNames1,L_astrPropValues1, 1, False)
The problem with this is that it only finds the text of the currently shown item in the combobox. So if "1800-3200 Hz" is not shown in the combobox, it returns nothing.
I tried preceding the FindAllChildren with a ComboBox.Click, but it rolls up immediately before the FindAllChildren is executed.
Does anyone have any ideas on how I could make this work? Please let me know if you need more information
Best regards
Lars Lund Olsen
Denmark
I am trying to make testscripts for a WPF application. I would like to make a helper function, that receives a combobox object, and a text. If the text exists in the combobox items, it should select it. If the text does not exist it should return a False flag.
The text in the combobox is stored in a TextBlock object within the Combobox hierarchy, and the TextBlock has a property called "Text"
This is the code have so far:
Dim MyString
Dim L_astrPropNames1
Dim L_astrValueNames1
ReDim L_astrPropNames1(0)
L_astrPropNames1(0) = "Text"
ReDim L_astrPropValues1(0)
L_astrPropValues1(0) = "1800-3200 Hz"
MyString = mycombobox.FindAllChildren(L_astrPropNames1,L_astrPropValues1, 1, False)
The problem with this is that it only finds the text of the currently shown item in the combobox. So if "1800-3200 Hz" is not shown in the combobox, it returns nothing.
I tried preceding the FindAllChildren with a ComboBox.Click, but it rolls up immediately before the FindAllChildren is executed.
Does anyone have any ideas on how I could make this work? Please let me know if you need more information
Best regards
Lars Lund Olsen
Denmark