Solved

TListView with checkboxes and OwnerData

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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