Hi!
Sometimes (not reproduceable) I'm getting an NullRefException from
ListView.OnHandleDestroyed()-Method.
Can somebody tell me, why ListViewItemCollection.get_Item() is being
accessed, when the Handle of the ListView ist already destroyed?
...
3) System.NullReferenceException
2) ListViewItemCollection.get_Item(Int32 displayIndex)
1) ListView.OnHandleDestroyed(EventArgs e)
...
Thank you very much,
Christian
System.NullReferenceException: Der Objektverweis wurde nicht auf eine
Objektinstanz festgelegt.
at System.Windows.Forms.ListViewItemCollection.get_Item(Int32 displayIndex)
at System.Windows.Forms.ListView.OnHandleDestroyed(EventArgs e)
at System.Windows.Forms.Control.WmDestroy(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ListView.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc,
IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WmClose(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ListView.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at client.clientMDI.Main(String[] args) in D:\blablabla.cs:line 111
Matt Garven - 11 Feb 2005 01:07 GMT
Hi Christian,
ListViewItemCollection.get_Item() is being accessed during OnHandleDestroyed
because the ListView class copies your items out of a private hashtable into
an arraylist. The hashtable is used as part of a windows interop mechanism,
so your items would be unavailable to you after the Handle was destroyed
unless they were copied into the arraylist.
As for why the NullReferenceException is occurring, I don't know - I'd need
know more about what you're doing and how you're using the ListView.
If you wanted a quick fix, you could override OnHandleDestroyed and clear
your items before calling base - that may do the trick, although I think it
would be nicer to find out what's actually going on :)
Hope this helps.
Regards,
Matt Garven
> Hi!
>
[quoted text clipped - 43 lines]
> at System.Windows.Forms.Application.Run(Form mainForm)
> at client.clientMDI.Main(String[] args) in D:\blablabla.cs:line 111
Christian Wilhelm - 11 Feb 2005 08:31 GMT
Hi Matt!
Thank you very much for your Reply!
I will try this approach and when I found out what's happening, I will post
in this thread again.
Thank you,
Christian
> Hi Christian,
>
[quoted text clipped - 72 lines]
>> at System.Windows.Forms.Application.Run(Form mainForm)
>> at client.clientMDI.Main(String[] args) in D:\blablabla.cs:line 111