i have a project where i use multiple comboboxes with dynamic lists inside them. so i made a method for search inside the comboboxes by clicking in the combobox to drop it down and then typing the word i am looking for in text area of the combobox and list is changing with each character i type. the problem i am facing is when there is no match for the word i am looking for, the list in the combobox became empty and as soon as i click outside the combobox i get a "System.ArgumentOutOfRangeException" exception in "ComboBox.ObjectCollection.cs". to test the problem here is a test project using the same methods and events i use in my original project: https://github.com/Abdourealcf/ComboboxSearch to replicate the error just click on the combobox and type anything like "wwwwww" and imediately click outside the combobox. here is a video for more details: https://drive.google.com/file/d/1waCJMmLm7ByWdc3_WntOW8TMI_TjRsq2/view?usp=sharing Please help me. i have no clue what is causing the exception! here is the stack trace:
[Exception] System.Windows.Forms.dll!System.Windows.Forms.ComboBox.ObjectCollection.this[int].get(int index) Line 233 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.ComboBox.SelectedItem.get() Line 1054 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.ComboBox.Text.get() Line 1246 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.ComboBox.WmReflectCommand(ref System.Windows.Forms.Message m) Line 3737 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.ComboBox.WndProc(ref System.Windows.Forms.Message m) Line 3867 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) Line 67 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) Line 117 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, Interop.User32.WM msg, System.IntPtr wparam, System.IntPtr lparam) Line 370 C# [Exception] System.Windows.Forms.Primitives.dll!Interop.User32.SendMessageW(IHandle hWnd, Interop.User32.WM Msg, System.IntPtr wParam, System.IntPtr lParam) Line 23713 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.Control.ReflectMessage(System.IntPtr hWnd, ref System.Windows.Forms.Message m) Line 9918 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.Control.WmCommand(ref System.Windows.Forms.Message m) Line 11831 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) Line 13045 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) Line 1504 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.WndProc(ref System.Windows.Forms.Message m) Line 2090 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.Form.WndProc(ref System.Windows.Forms.Message m) Line 6632 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) Line 67 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) Line 117 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, Interop.User32.WM msg, System.IntPtr wparam, System.IntPtr lparam) Line 370 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m) Line 516 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.ComboBox.ComboBoxChildNativeWindow.WndProc(ref System.Windows.Forms.Message m) Line 62 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, Interop.User32.WM msg, System.IntPtr wparam, System.IntPtr lparam) Line 370 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.Interop.Mso.IMsoComponentManager.FPushMessageLoop(System.UIntPtr dwComponentID, Interop.Mso.msoloop uReason, void* pvLoopData) Line 346 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Interop.Mso.msoloop reason, System.Windows.Forms.ApplicationContext context) Line 1117 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Interop.Mso.msoloop reason, System.Windows.Forms.ApplicationContext context) Line 981 C# [Exception] System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) Line 1188 C# [Exception] ComboboxSearch.dll!ComboboxSearch.Program.Main() Line 14 C# System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, Interop.User32.WM msg, System.IntPtr wparam, System.IntPtr lparam) Line 381 C#
As a work around i did this:
and in my
comboBox1_KeyUpevent i added:old_txt = comboBox1.Text;I know its ugly but it does fix the problem.