Solved

TListView with checkboxes and OwnerData

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

864 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now