{"record":{"id":"a40b49b4cd190d33","repo":"dotnet/wpf","slug":"0-is-not-a-valid-value-for-this-control","errorCode":null,"errorMessage":"'{0}' is not a valid value for this control.","messagePattern":"'(.+?)' is not a valid value for this control\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsEditBox.cs","lineNumber":282,"sourceCode":"            // Ensure that the edit box and all its parents are enabled.\n            Misc.CheckEnabled(_hwnd);\n\n            int styles = WindowStyle;\n\n            if (Misc.IsBitSet(styles, NativeMethods.ES_READONLY))\n            {\n                throw new InvalidOperationException(SR.ValueReadonly);\n            }\n\n            // check if control only accepts numbers\n            if (Misc.IsBitSet(styles, NativeMethods.ES_NUMBER))\n            {\n                // check if string contains any non-numeric characters.\n                foreach (char ch in str)\n                {\n                    if (char.IsLetter (ch))\n                    {\n                        throw new ArgumentException(SR.Format(SR.NotAValidValue, str), \"val\");\n                    }\n                }\n            }\n\n            // Text/edit box should not enter more characters than what is allowed through keyboard.\n            // Determine the max number of chars this editbox accepts\n            int result = Misc.ProxySendMessageInt(_hwnd, NativeMethods.EM_GETLIMITTEXT, IntPtr.Zero, IntPtr.Zero);\n            // A result of -1 means that no limit is set.\n            if (result != -1 && result < str.Length)\n            {\n                throw new InvalidOperationException (SR.OperationCannotBePerformed);\n            }\n\n            // Send the message...\n            result = Misc.ProxySendMessageInt(_hwnd, NativeMethods.WM_SETTEXT, IntPtr.Zero, new StringBuilder(str));\n            if (result != 1)\n            {\n                throw new InvalidOperationException(SR.OperationCannotBePerformed);","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsEditBox.cs#L264-L300","documentation":"The Win32 edit box proxy throws ArgumentException(NotAValidValue) from IValueProvider.SetValue when the control has the ES_NUMBER style but the supplied string contains alphabetic characters. A numeric-only edit control cannot accept non-numeric text.","triggerScenarios":"Calling IValueProvider.SetValue on a WindowsEditBox whose window styles include ES_NUMBER, with a string containing any letter (char.IsLetter).","commonSituations":"Automating numeric input fields (age, quantity, port) and passing formatted values like '12abc', 'N/A', or values with letters from a spreadsheet; localized number formatting carrying letter suffixes.","solutions":["Strip or validate the string so it contains only numeric characters before calling SetValue.","Pass the number formatted as digits only, e.g. value.ToString(CultureInfo.InvariantCulture).","If non-numeric text is genuinely needed, recreate the edit control without ES_NUMBER.","Catch ArgumentException and surface a clear 'numeric field' validation message to the user."],"exampleFix":"// before\nvaluePattern.SetValue(\"12 items\"); // ArgumentException: not a valid value\n// after\nstring numeric = new string(raw.Where(char.IsDigit).ToArray());\nif (numeric.Length > 0) valuePattern.SetValue(numeric);","handlingStrategy":"validation","validationCode":"if (raw.Any(char.IsLetter))\n    throw new ArgumentException(\"Numeric field requires digits only\");\nvaluePattern.SetValue(raw);","typeGuard":null,"tryCatchPattern":"try { vp.SetValue(s); }\ncatch (ArgumentException) { /* reject non-numeric input upstream */ }","preventionTips":["Sanitize input to digits for ES_NUMBER controls.","Use InvariantCulture number formatting.","Validate at the data-entry boundary, not the UI."],"tags":["uiautomation","winforms","editbox","argument","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}