Using checkbox in virtual mode listview

2.5k views Asked by At

I am learning to make virtual mode listview. So far my problem is I can not use checkbox in the listview. I already read a link from http://delphi-kb.blogspot.com/2011/02/draw-checkboxes-in-virtual-mode.html but I don't see any checkbox. Any idea?

1

There are 1 answers

7
Jens Mühlenhoff On BEST ANSWER

Apparently you have to draw the CheckBoxes yourself when OwnerData is enabled (as mentioned in the article linked in the question).

So you have to set OwnerDraw to True (in addition to OwnerData, the two are independed flags!) and draw the CheckBoxes yourself in the OnCustomDrawItem event.

Update:

It seems that this is not entirely true, the OnCustomDrawItem event is also fired in the case OwnerDraw = False.

http://docwiki.embarcadero.com/VCL/XE2/en/ComCtrls.TListView.OnCustomDrawItem

Update 2:

The code linked in the question only works when OwnerDraw = False and CheckBoxes = True.

Otherwise the VCL doesn't reserve space on the left to draw CheckBoxes.

BTW: You might be better of using a more advanced component like TVirtualTreeView from Mike Lischke.