Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2005

Tip: Looking for answers? Try searching our database.

Exception in ListView.OnHandleDestroyed

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Christian Wilhelm - 10 Feb 2005 08:51 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.