|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Too many items in listbox?I've been periodically getting an 'odd' error message that I don't understand. Normally I can 'pseudo' fix the problem by doing something that seems entirely unrelated to the problem, but the error keeps popping up periodically. Its an out of memory exception, and it pops up here and there. It keeps complaining that there are 'too many items in list box' or 'too many items in combo box', etc. The error *sounds* straight forward enough, unfortunately, I have <<100 items in the list box/combo box in question. Not sure if it makes a difference, or if it was a bad idea to begin with, but I've been populating the list with custom objects (not strings). They aren't all that big objects. Not sure the actual exact size of them, but the XML file that is generated by the largest is 7kB. Is this making any sense to anyone? Ringing any bells? (the exception detail follows) Dale System.OutOfMemoryException was unhandled Message="List box contains too many items." Source="System.Windows.Forms" StackTrace: at System.Windows.Forms.ListBox.NativeAdd(Object item) at System.Windows.Forms.ListBox.OnHandleCreated(EventArgs e) at System.Windows.Forms.Control.WmCreate(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ListBox.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam) at System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam) at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp) at System.Windows.Forms.Control.CreateHandle() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ContainerControl.WndProc(Message& m) at System.Windows.Forms.Form.WmShowWindow(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam) at System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam) at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp) at System.Windows.Forms.Control.CreateHandle() at System.Windows.Forms.Form.CreateHandle() at System.Windows.Forms.Control.get_Handle() at System.Windows.Forms.Form.SetVisibleCore(Boolean value) at System.Windows.Forms.Control.Show() at AnatomyAlive.frmMain.frmMain_Load(Object sender, EventArgs e) in E:\Users\UCVM Student\Documents\Visual Studio 2008\Projects\AnatomyAlive\AnatomyAlive\MDIParent1.vb:line 74 at System.EventHandler.Invoke(Object sender, EventArgs e) at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Form.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ContainerControl.WndProc(Message& m) at System.Windows.Forms.Form.WmShowWindow(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, Int32 wParam, Int32 lParam) at System.Windows.Forms.Form.SetVisibleCore(Boolean value) at System.Windows.Forms.Control.set_Visible(Boolean value) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(ApplicationContext context) at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) at AnatomyAlive.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel) at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly() at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData) at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext) at System.Activator.CreateInstance(ActivationContext activationContext) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: Apparently I should Google a little harder before posting... I solved the
problem. Apparently, if the .ToString function returns a null value, you'll get this message. -- Solution Make sure .ToString doesn't return a null. No idea why this would give a 'Too many items in listbox' error though (as opposed to something more descriptive). Dale Show quoteHide quote "Dale Atkin" <labrad***@ibycus.com> wrote in message news:eQH1gyi5JHA.5728@TK2MSFTNGP03.phx.gbl... > I'm coding in VB.net > > I've been periodically getting an 'odd' error message that I don't > understand. Normally I can 'pseudo' fix the problem by doing something > that seems entirely unrelated to the problem, but the error keeps popping > up periodically. > > Its an out of memory exception, and it pops up here and there. It keeps > complaining that there are 'too many items in list box' or 'too many items > in combo box', etc. The error *sounds* straight forward enough, > unfortunately, I have <<100 items in the list box/combo box in question. > > Not sure if it makes a difference, or if it was a bad idea to begin with, > but I've been populating the list with custom objects (not strings). They > aren't all that big objects. Not sure the actual exact size of them, but > the XML file that is generated by the largest is 7kB. > > Is this making any sense to anyone? Ringing any bells? (the exception > detail follows) > > Dale > > System.OutOfMemoryException was unhandled > Message="List box contains too many items." > Source="System.Windows.Forms" > StackTrace: > at System.Windows.Forms.ListBox.NativeAdd(Object item) at > System.Windows.Forms.ListBox.OnHandleCreated(EventArgs e) at > System.Windows.Forms.Control.WmCreate(Message& m) at > System.Windows.Forms.Control.WndProc(Message& m) at > System.Windows.Forms.ListBox.WndProc(Message& m) at > System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) > at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) > at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 > msg, IntPtr wparam, IntPtr lparam) at > System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 > dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 > x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef > hMenu, HandleRef hInst, Object pvParam) at > System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, > String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 > y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, > HandleRef hInst, Object pvParam) at > System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp) at > System.Windows.Forms.Control.CreateHandle() at > System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at > System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at > System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at > System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at > System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at > System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at > System.Windows.Forms.Control.CreateControl() at > System.Windows.Forms.Control.WmShowWindow(Message& m) at > System.Windows.Forms.Control.WndProc(Message& m) at > System.Windows.Forms.ScrollableControl.WndProc(Message& m) at > System.Windows.Forms.ContainerControl.WndProc(Message& m) at > System.Windows.Forms.Form.WmShowWindow(Message& m) at > System.Windows.Forms.Form.WndProc(Message& m) at > System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) > at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) > at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 > msg, IntPtr wparam, IntPtr lparam) at > System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 > dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 > x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef > hMenu, HandleRef hInst, Object pvParam) at > System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, > String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 > y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, > HandleRef hInst, Object pvParam) at > System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp) at > System.Windows.Forms.Control.CreateHandle() at > System.Windows.Forms.Form.CreateHandle() at > System.Windows.Forms.Control.get_Handle() at > System.Windows.Forms.Form.SetVisibleCore(Boolean value) at > System.Windows.Forms.Control.Show() at > AnatomyAlive.frmMain.frmMain_Load(Object sender, EventArgs e) in > E:\Users\UCVM Student\Documents\Visual Studio > 2008\Projects\AnatomyAlive\AnatomyAlive\MDIParent1.vb:line 74 at > System.EventHandler.Invoke(Object sender, EventArgs e) at > System.Windows.Forms.Form.OnLoad(EventArgs e) at > System.Windows.Forms.Form.OnCreateControl() at > System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at > System.Windows.Forms.Control.CreateControl() at > System.Windows.Forms.Control.WmShowWindow(Message& m) at > System.Windows.Forms.Control.WndProc(Message& m) at > System.Windows.Forms.ScrollableControl.WndProc(Message& m) at > System.Windows.Forms.ContainerControl.WndProc(Message& m) at > System.Windows.Forms.Form.WmShowWindow(Message& m) at > System.Windows.Forms.Form.WndProc(Message& m) at > System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) > at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) > at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 > msg, IntPtr wparam, IntPtr lparam) at > System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 > msg, Int32 wParam, Int32 lParam) at > System.Windows.Forms.Form.SetVisibleCore(Boolean value) at > System.Windows.Forms.Control.set_Visible(Boolean value) at > System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 > reason, ApplicationContext context) at > System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 > reason, ApplicationContext context) at > System.Windows.Forms.Application.Run(ApplicationContext context) at > Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() > at > Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() > at > Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] > commandLine) at AnatomyAlive.My.MyApplication.Main(String[] Args) in > 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 at > System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at > System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) at > System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel) at > System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly() at > System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext > activationContext, String[] activationCustomData) at > System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext > activationContext) at System.Activator.CreateInstance(ActivationContext > activationContext) at > Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() > at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at > System.Threading.ExecutionContext.Run(ExecutionContext executionContext, > ContextCallback callback, Object state) at > System.Threading.ThreadHelper.ThreadStart() > InnerException: > Dale Atkin wrote:
Show quoteHide quote > I'm coding in VB.net The only thing I can figure out from here is that you seem to Show the Form> > I've been periodically getting an 'odd' error message that I don't > understand. Normally I can 'pseudo' fix the problem by doing > something that seems entirely unrelated to the problem, but the error > keeps popping up periodically. > > Its an out of memory exception, and it pops up here and there. It > keeps complaining that there are 'too many items in list box' or 'too > many items in combo box', etc. The error *sounds* straight forward > enough, unfortunately, I have <<100 items in the list box/combo box > in question. > Not sure if it makes a difference, or if it was a bad idea to begin > with, but I've been populating the list with custom objects (not > strings). They aren't all that big objects. Not sure the actual exact > size of them, but the XML file that is generated by the largest is > 7kB. > Is this making any sense to anyone? Ringing any bells? (the exception > detail follows) inside Load - which doesn't make sense as Load is raised because Show has already been called before. > System.Windows.Forms.Control.Show() at Are you using multiple threads?> AnatomyAlive.frmMain.frmMain_Load(Object sender, EventArgs e) in > E:\Users\UCVM Student\Documents\Visual Studio > 2008\Projects\AnatomyAlive\AnatomyAlive\MDIParent1.vb:line 74 at Armin "Armin Zingler" <az.nospam@freenet.de> wrote in message Those were two different forms. MDIParent, calls Show on a child form during news:uh8kBJj5JHA.4896@TK2MSFTNGP04.phx.gbl... > The only thing I can figure out from here is that you seem to Show the > Form > inside Load - which doesn't make sense as Load is raised because Show has > already been called before. > >> System.Windows.Forms.Control.Show() at >> AnatomyAlive.frmMain.frmMain_Load(Object sender, EventArgs e) in >> E:\Users\UCVM Student\Documents\Visual Studio >> 2008\Projects\AnatomyAlive\AnatomyAlive\MDIParent1.vb:line 74 at its load event (default behaviour if certain start up conditions are met, so that the user isn't presented with a blank screen). > Nope.> Are you using multiple threads? > In case anyone reads this and misses the other response sent at the same time. I tracked the problem down. If "ToString" on the class I'm adding to the listbox returns "Nothing", the error will show up. I modified "ToString" so that it will always return something. Still no idea why this triggers the error the way it does though. To replicate the odd error message, try the following, with a button (Button1) and a combobox (ComboBox1) on a form: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim s As New Something ComboBox1.Items.Add(s) End Sub End Class Public Class Something Public Overrides Function ToString() As String Return vbNullString End Function End Class Passing a null string directly, yields a much more intelligent error message, that tells you exactly what is wrong. Dale |
|||||||||||||||||||||||