Attaching unmanaged window handle with managed object

Friends,
I've a Win32 handle of a window of type SysListView32. I want to attach this Window handle to .NET managed object of type ListView.

Back during the days of MFC/C++ this can be done something like:

CListView *pListView = (CListView *)CWnd::FromHandle(hListView);
int itemCount = pListView->GetItemCount();

How can i do the same in C# The reason behind doing so is that i want to call the methods of ListView object to perform operations on ListViewControl such as getting number of items, clearing all items e.t.c.



Answer this question

Attaching unmanaged window handle with managed object

  • Kolf

    I don't think you can. The ListView control won't let you assign the Handle property. .NET controls need to keep control over the handle so they can re-create them when the control's style changes.



  • Attaching unmanaged window handle with managed object