Solved

TListView with checkboxes and OwnerData

Posted on 2003-10-23
4
4,798 Views
Last Modified: 2007-12-19
I have a simple TListView, set to ViewStyle=vsReport.
I have Checkboxes=true, which works without problems so far.

Now I want to use OwnerData, so I implemented my OnData event.
The data is showing perfectly. Except one thing: the checkboxes are not showing.

To reproduce:
- Add TListView
- Set ViewStyle=vsReport
- Set Checkboxes=true
- Set OwnerDraw=true
- In form init code, set ListView1.Items.Count=10
- In ListView1OnData, set Item.Caption := 'Hello World'

Does anyone know how I can use checkboxes & ownerdraw in a standard TListView?
0
Comment
Question by:ccrdude
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 9605500
Drawing checkboxes in a listview or other screen item with a canvas is quite easy. Use the Windows API function DrawFrameControl() to draw it for you. The function requires several parameters:
DC: HDC -> The handle of the canvas where you want to draw the checkbox.
Rect: TRect -> The location and size of the checkbox.
uType: UINT -> The type of control you want to draw. Use DFC_BUTTON for a checkbox.
uState: UINT -> The state of the control. Use DFCS_BUTTONCHECK for a clear checkbox and use DFCS_BUTTONCHECK or DFCS_CHECKED for a checked checkbox. Add DFCS_INACTIVE to make it appear as inactive.

Use the OnDraw events to draw these controls on your listview and the OnClick or whatever other method to check/uncheck them.
0
 
LVL 2

Author Comment

by:ccrdude
ID: 9605570
Thanks! But... I found an error in what I wrote above. I wrote twice OwnerData, but one time accidently OwnerDraw...
I actually don't want/need OwnerDraw, just OwnerData. Does your answer mean that I have to use OwnerDraw to draw the Checkbox if I use OwnerData, or were you just mislead by my mistake in mentioning OwnerDraw?

(anyway, the function you referred to may come in handy in another situation... I wish I had known it a year ago :) )
0
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 155 total points
ID: 9605958
Oh, no OwnerDraw? Okay... If I'm not mistaken then when OwnerData is true, the Delphi component will not set the checkbox of the underlying Windows control. So I checked the MSDN site about the LVS_OWNERDATA value for virtual listviews. It says, quote:
"A virtual list view is a list-view control that has the LVS_OWNERDATA style. This style enables the control to handle millions of items because the owner receives the burden of managing item data. This allows you to use the virtual list-view control with large databases of information, where specific methods of data access are already in place.
A virtual list-view control maintains very little item information itself. Except for the item selection and focus information, the owner of the control must manage all item information. Other processes request item information from the owner by using LVN_GETDISPINFO notification messages.
Because this type of list control is intended for large data sets, it is recommended that you cache requested item data to improve retrieval performance. The list view provides a cache-hinting mechanism to assist in optimizing the cache. The hint is implemented in the form of an LVN_ODCACHEHINT notification message."
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/listview/styles.asp for the complete overview...

Thus, it is unlikely that a virtual listview will be able to maintain the state of any checkbox on it. You'll have to draw them yourself, I guess...

I was not mistaken by that OwnerData/OwnerDraw thingie, btw. I knew I had looked at this myself once, a long while ago. I just could not remember why I used OwnerDraw to draw the checkbox. Now I know... :-)
You can also use that function to draw other kinds of controls, btw...
0
 
LVL 2

Author Comment

by:ccrdude
ID: 9609683
If the listview already gets text & image etc. using OnData, why not the checkbox state?... like TVirtualStringTree does, which I now use since I already have it in other places in the project. But thanks for your detailed description, which I'Ve stored for future reference :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month6 days, 4 hours left to enroll

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question