Virtual ListView using the Compact Framework?

M

Mark Erikson

Okay, I've got a question for you folks. I'm currently working on
creating a C# version of Tillanosoft's TGetFile open/save dialogs
(they don't work with C#, and I'm a cheapskate anyway). I've managed
to solve the majority of my problems, mostly through insane amounts of
Googling, but this one I haven't been able to find an answer for.

The major timewaster in my dialog right now is adding files into the
ListView.ListViewItemCollection. Since the CF ListView doesn't have a
..Sort() method, I've been doing sorting on my own, and managed to get
it pretty fast. However, this means I have to .Clear() the ListView
each time I sort it, and .Add() every item back into the list in the
newly sorted order. I've been testing my dialog against the \Windows
directory, which currently contains about 750 items. Adding those 750
items into the ListView can take anywhere from 5600 milliseconds to
11000 milliseconds - far too long to be acceptable.

As a result, I've been reading up on "virtual listviews". I
understand the basic concept of them, and even found an example in C#
at windowsforms.net. Here's where my problem comes in. The example I
found overrides the .CreateParam sproperty and sets its style to
LVS_OWNERDATA, which is necessary for it to be a virtual listview.
Naturally, the Compact Framework ListView doesn't support
..CreateParams, and apparently doesn't support other styles either.

So, here's my question: is there ANY way possible to set the Compact
Framework ListView style to LVS_OWNERDATA? I can get a handle and do
a SendMessage if necessary. Any help would be GREATLY appreciated,
including possible ideas for optimizing adding ListViewItems or other
techniques for doing a virtual listview with the Compact Framework.

If this can't be done, well... does anyone have any suggestions as to
how to go about creating my own ListView control that I could make
virtual, something like wrapping the MFC or built-in ones? I think
the biggest issue there would be trying to dealing with all the
messages and handling the imagelists and stuff. I really don't want
to have to do that if I can avoid it.

Anyway, thanks in advance for any help you guys can provide.

Mark Erikson
 
M

Mark Erikson

Hmm. Interesting. Definitely a useful article. I've been through
the OpenNetCF site before, but thanks for the link.

As it turns out, I actually figured out how to set the LVS_OWNERDATA
style about an hour after I posted that request. Here's what I did:

[DllImport("coredll.dll", CharSet=CharSet.Auto,
EntryPoint="SetWindowLong")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint
dwNewLong);

[DllImport("coredll")]
public static extern IntPtr GetFocus();


int GWL_STYLE = -16;
uint LVS_OWNERDATA = 0x1000

listView1.Focus();
IntPtr pLV = GetFocus();
SetWindowLong(pLV, GWL_STYLE, LVS_OWNERDATA);


I haven't had a chance to do anything more than that thus far, but it
definitely made it owner-drawn.

When I finish this project, I plan on making several posts to this
newsgroup to make the lessons I've learned available. I've had to do
a LOT of hard searching to come up with some of my solutions, and I
hope to make things easier for others in the future. I'm also
planning to make the Open/Save dialog I'm working on freely available
as well.

Mark Erikson
 
M

Mark Erikson

If there's one lesson I've been learning through this project, it's
that I should never assume I've got something completely figured out.
I'm able to send LVS_OWNERDATA to the listview, and I've done all I
can to convert the sample I found over to the Compact Framework, but
thus far it doesn't do anything beyond sit there. I'm guessing it's
an issue with WndProc. I doodled a bit with that, but no results so
far, and writing my own is looking more and more likely.

I suppose I will ask this, though: I've seen several messages that say
to inherit from MesssageWindow and override WndProc. Did that. Now,
is that supposed to actually override my FORM's WndProc, or is the
MessageWindow doing its own thing entirely?

In the meantime, I think I'll take a stab at writing my own.

Thanks again for any help.

Mark Erikson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top