//------------------------------------------------------ // // Patterns Implementation // //------------------------------------------------------ #region ProxySimple Interface // Returns a pattern interface if supported. internal override object GetPatternProvider(AutomationPattern iid) { if (iid == InvokePattern.Pattern && WindowsListView.ListViewInvokable(_hwnd)) { return(this); } if (iid == SelectionItemPattern.Pattern) { return(this); } if (iid == ValuePattern.Pattern && WindowsListView.ListViewEditable(_hwnd)) { return(this); } if (iid == GridItemPattern.Pattern && IsImplementingGrid(_hwnd)) { return(this); } if (iid == TogglePattern.Pattern && IsItemWithCheckbox(_hwnd, _item)) { return(CreateListViewItemCheckbox()); } if (iid == ScrollItemPattern.Pattern && WindowScroll.IsScrollable(_hwnd)) { return(this); } return(null); }
// ------------------------------------------------------ // // Constructors // //------------------------------------------------------ #region Constructors internal ListViewSubItem(IntPtr hwnd, ProxyFragment parent, int item, int itemParent) : base(hwnd, parent, item) { // Is used to discriminate between items in a collection. _itemParent = itemParent; _cControlType = WindowsListView.ListViewEditable(hwnd) ? ControlType.Edit : ControlType.Text; }
//------------------------------------------------------ // // Patterns Implementation // //------------------------------------------------------ #region ProxySimple Interface // Returns a pattern interface if supported. internal override object GetPatternProvider(AutomationPattern iid) { if (iid == GridItemPattern.Pattern) { return(this); } // Only the first element is editable if (iid == ValuePattern.Pattern && _item == 0 && WindowsListView.ListViewEditable(_hwnd)) { return(this); } if (iid == TableItemPattern.Pattern) { return(this); } return(null); }
internal static void SetValue(string val, IntPtr hwnd, int item) { // PerSharp/PreFast will flag this as warning 6507/56507: Prefer 'string.IsNullOrEmpty(val)' over checks for null and/or emptiness. // An empty strings is valued here, while a null string is not. // Therefore we can not use IsNullOrEmpty() here, suppress the warning. #pragma warning suppress 6507 if (val == null) { throw new ArgumentNullException("val"); } if (!WindowsListView.ListViewEditable(hwnd)) { throw new InvalidOperationException(SR.Get(SRID.ValueReadonly)); } Misc.SetFocus(hwnd); // set focus to the item WindowsListView.SetItemFocused(hwnd, item); // retrieve edit window IntPtr hwndEdit = WindowsListView.ListViewEditLabel(hwnd, item); if (IntPtr.Zero == hwndEdit) { throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed)); } // re-use editbox proxy to do the job // Note: we will pass null and -1 for some of the parameters // this is ok, since the only thing that matters to us is an ability to set the text // and these parameters irrelevant for our task WindowsEditBox editBox = new WindowsEditBox(hwndEdit, null, -1); // get value pattern IValueProvider valueProvider = editBox.GetPatternProvider(ValuePattern.Pattern) as IValueProvider; // try to set user-provided text bool setValueSucceeded = false; try { valueProvider.SetValue(val); setValueSucceeded = true; } finally { // even if there is a problem doing SetValue need to exit // editing mode (e.g. cleanup from editing mode). FinishEditing(setValueSucceeded, hwnd, hwndEdit); } // Need to give some time for the control to do all its processing. bool wasTextSet = false; for (int i = 0; i < 10; i++) { System.Threading.Thread.Sleep(1); // Now see if the item really got set. if (val.Equals(ListViewItem.GetText(hwnd, item, 0))) { wasTextSet = true; break; } } if (!wasTextSet) { throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed)); } }