Get the selected item in combobox

Jun 19, 2012 at 3:59 PM

I am trying to get the selected item from combobox using comboBox.SelectedItemText

But it is returning the null value. Is there any solution?

Jun 20, 2012 at 5:41 PM

Is it a WPF ComboBox by chance?

Jun 21, 2012 at 8:21 AM
Edited Jun 21, 2012 at 8:23 AM

Hi

have you tried to open the context menu of ComboBox first?

in most cases the list is not fully initialized and so selectedItemTest returns null.

But if you open and close the context menu the items will be initialized.

 

open with click();

close with Enter "Esc" or Click on Titelbar of the parent window

@wwarwood in my opinion to use ComboBox or WPFCombobox has no difference, but this might be only right in my case.

 

Throndorin

Jun 21, 2012 at 8:53 AM
Throndorin wrote:

Hi

have you tried to open the context menu of ComboBox first?

in most cases the list is not fully initialized and so selectedItemTest returns null.

But if you open and close the context menu the items will be initialized.

 

open with click();

close with Enter "Esc" or Click on Titelbar of the parent window

@wwarwood in my opinion to use ComboBox or WPFCombobox has no difference, but this might be only right in my case.

 

Throndorin

Yes. The focus was needed on the combobox and hence it was returning the null value. Before getting the combobox selected item need to focus it. .Click() works.

Jul 5, 2012 at 3:21 PM

For the applications I automate, this behavior only exhibits itself on WPF comboboxes...