예제 #1
0
        public void Select(string selection)
        {
            if (selection.Equals(string.Empty))
            {
                foreach (AutomationElement element in _selectionPattern.GetSelection())
                {
                    new SelectionItemPatternWrapper(element).RemoveFromSelection();
                }
            }
            else
            {
                bool found = false;
                _expandCollapsePattern.Expand();

                foreach (AutomationElement listItem in AllItemElements())
                {
                    if (listItem.GetCurrentPropertyValue(AutomationElement.NameProperty).Equals(selection))
                    {
                        new SelectionItemPatternWrapper(listItem).Select();
                        found = true;
                        break;
                    }
                }
                _expandCollapsePattern.Collapse();
                if (!found)
                {
                    throw new FailureToFindException("Failed to find an element in this ComboBox with a value of " + selection +
                                                     ". Please use the ToString() value of the element for selection, or string.Empty to clear the selection. If you want " +
                                                     "to select arbitrary text in an editable ComboBox, please use the EditableComboBox.Text method.");
                }
            }
        }
예제 #2
0
 private IEnumerable GetSelectedElements()
 {
     return(_selectionPattern.GetSelection());
 }