// Sets the text of the edit part of the Combo void IValueProvider.SetValue(string str) { // Ensure that the window and all its parents are enabled. Misc.CheckEnabled(_hwnd); // piggy-back on win32editbox proxy NativeMethods.COMBOBOXINFO cbInfo = new NativeMethods.COMBOBOXINFO(NativeMethods.comboboxInfoSize); if (GetComboInfo(_hwnd, ref cbInfo) && SafeNativeMethods.IsWindowVisible(cbInfo.hwndItem)) { WindowsEditBox editBox = new WindowsEditBox(cbInfo.hwndItem, null, -1); IValueProvider valueProvider = (IValueProvider)editBox.GetPatternProvider(ValuePattern.Pattern); // try to set user-provided text valueProvider.SetValue(str); // Let the parent know that the value has change, to allow the parent to do any processing it needs // to do on value change. IntPtr hwndParent = Misc.GetParent(_hwnd); if (hwndParent != IntPtr.Zero) { int id = Misc.GetWindowId(_hwnd); IntPtr wParam = new IntPtr(NativeMethods.Util.MAKELONG(id, NativeMethods.CBN_EDITUPDATE)); Misc.ProxySendMessage(hwndParent, NativeMethods.WM_COMMAND, wParam, _hwnd); } return; } throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed)); }
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)); } }
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)); } }
// Sets the text of the edit part of the Combo void IValueProvider.SetValue (string str) { // Ensure that the window and all its parents are enabled. Misc.CheckEnabled(_hwnd); // piggy-back on win32editbox proxy NativeMethods.COMBOBOXINFO cbInfo = new NativeMethods.COMBOBOXINFO(NativeMethods.comboboxInfoSize); if (GetComboInfo(_hwnd, ref cbInfo) && SafeNativeMethods.IsWindowVisible(cbInfo.hwndItem)) { WindowsEditBox editBox = new WindowsEditBox(cbInfo.hwndItem, null, -1); IValueProvider valueProvider = (IValueProvider) editBox.GetPatternProvider (ValuePattern.Pattern); // try to set user-provided text valueProvider.SetValue (str); // Let the parent know that the value has change, to allow the parent to do any processing it needs // to do on value change. IntPtr hwndParent = Misc.GetParent(_hwnd); if (hwndParent != IntPtr.Zero) { int id = Misc.GetWindowId(_hwnd); IntPtr wParam = new IntPtr(NativeMethods.Util.MAKELONG(id, NativeMethods.CBN_EDITUPDATE)); Misc.ProxySendMessage(hwndParent, NativeMethods.WM_COMMAND, wParam, _hwnd); } return; } throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed)); }