Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I cannot get the combo box list. #609

Open
RunbeckDave opened this issue Dec 29, 2023 · 2 comments
Open

I cannot get the combo box list. #609

RunbeckDave opened this issue Dec 29, 2023 · 2 comments

Comments

@RunbeckDave
Copy link

Describe the bug
Tried comboBox.Select
Extensions SelectItem - Using the Patter IExpandCollapsePattern
Extension ChooseItem - This worked fabulously before I was laid off last Xmas. Now I have been rehired, but the combo box on an old vb form is no longer working.

Code snippets
//loginForm.LoginTo.Select(loginInformation.LoginTo);
//loginForm.LoginTo.SelectItem(loginInformation.LoginTo)
loginForm.LoginTo.ChooseItem(loginInformation.LoginTo);
loginForm.LoginButton.Invoke();

    public static void SelectItem(this ComboBox comboBox, string selection)
    {
        IExpandCollapsePattern pattern = comboBox.Patterns.ExpandCollapse.Pattern;
        pattern.Expand();
        comboBox.Select(selection);
    }

public static void ChooseItem(this ComboBox comboBox, string selection)
{
comboBox.Focus();
ComboBoxItem[] comboBoxItems = comboBox.Items;
foreach (ComboBoxItem item in comboBoxItems)
{
if (item.Text == selection)
{
if (comboBox.ExpandCollapseState != ExpandCollapseState.Expanded) comboBox.Expand();
item.Select();
if (comboBox.ExpandCollapseState == ExpandCollapseState.Expanded) comboBox.Collapse();
return;
}
}
}

Screenshots
image

Additional context
Add any other context about the problem here.

@tomczakmarcel
Copy link

Try selecting using Id
Don't use '==' when comparing strings, use string.Equals()

@Roemer
Copy link
Member

Roemer commented Mar 8, 2024

Are there any items in comboBoxItems? Did you maybe switch from UIA2 to UIA3 or the other way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants