better component than ListVIew

A

--== Alain ==--

Hi,

Several months ago i've asked some information about the best way how to
have some particular columns (progress bar, checkbox, images, color
picker,...) in a ListView component.

It seems that ListView is a complex component and a lot of people advise
to build a custom component but not from ListVIew itself.

Some use a datagrid component as base component, some build a component
from scratch, and so on.

I know that some will write that it is stupid to reinvent the hot water,
but it is for training purpose.

therefore i would like to know what is the component trend to improve
ListView features ? Datagrid, custom component, and so on...

thanks a lot,

Al.
 
T

Tamas Demjen

--== Alain ==-- said:
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
 
B

Ben Voigt

Tamas Demjen said:
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.

The VisualStyle stuff doesn't gracefully degrade when themes are disabled.
It doesn't work in design mode either.
 
T

Tamas Demjen

Ben said:
The VisualStyle stuff doesn't gracefully degrade when themes are disabled.
It doesn't work in design mode either.

You mean if I use VisualStyleRenderer to paint my own list view header
or tree collapse/expand icons, it won't work on Windows 2000, or when XP
themes are disabled? I have to look into this.

Tom
 
T

Tamas Demjen

--== Alain ==-- said:
thx a lot for your info.
But why to create it from Panel ?

I'm not a professional .NET visual control developer, that's not my main
expertise. There are lower level classes to inherit from. I don't know
what others are using to implement totally custom painted components.

I used Panel to implement an image editor, a thumbnail viewer and a
special tree view (so unique that it couldn't be based on the standard
tree control).

Using Panel has a few advantages. It already has a graphics to provide a
drawing surface. It's a container for child controls, so you can easily
insert other controls on it. It has built-in double buffering in .NET
2.0. It has the ability to handle the scrolling automatically, by
showing horizontal and vertical scroll bars as needed. All you have to
do is provide the size of your virtual canvas, and if it doesn't fit, it
inserts the scroll bars automatically. The control already has useful
events and properties, such as a bevel and other visual styles.

I'm not that familiar with the .NET framework's component hierarchy.
Maybe someone else can suggest you a base to inherit from, depending on
your needs. I just found that Panel always works for completely custom
painted components, if you don't have a better idea. If you just want to
tweak a list view a little bit, inherit from ListView and implement the
custom painting of the items.

Tom
 

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