Solved

TListView with checkboxes and OwnerData

Posted on 2003-10-23
4
4,629 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Internet Explorer View Settings Question 15 116
Send message from delphi to whatsapp, is it possible? 3 1,636
creating threads in delphi 1 130
Delphi and Access based Enumeration 9 70
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

792 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