--== Alain ==-- wrote:
It seems that ListView is a complex component and a lot of people advise
to build a custom component but not from ListVIew itself.
In case ListView can't do what you need, it's better to create your own
component from scratch. Inherit from Panel, custom draw the entire
component sing double buffering. Capture the mouse and keyboard events
and process them yourself. It's quite a bit of work, but you'll have
full control, and none of the burdenful issues of the original ListView.
It's not nearly as hard to build such a custom component as it may first
seem, but it will take several days at the very minimum.
A few tips for you:
- Do this in the constructor to eliminate flickering due to double paint:
SetStyle(ControlStyles::Opaque, true);
SetStyle(ControlStyles::UserPaint, true);
SetStyle(ControlStyles::AllPaintingInWmPaint, true);
- Call ControlPaint::DrawFocusRectangle to paint your own focus rectangle.
- Here's how to ensure an off-screen bitmap for double buffering:
if(bmp == nullptr)
{
bmp = gcnew Bitmap(ClientRectangle.Width, ClientRectangle.Height);
gr = Graphics::FromImage(bmp);
}
You paint everything to this bitmap, then you use DrawImageUnscaled(bmp,
0, 0) to show it on the screen.
- Take a look at VisualStyles::VisualStyleElement and
VisualStyles::VisualStyleRenderer to render standard Windows elements on
the screen, such as a list view header, buttom, check box, tree
collapse/expand icons, and much more. They're only available in .NET
2.0+, but but .NET 1.x is so primitive you can't do any serious work
with it anyway.
Tom