3

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?

menjaraz
  • 7,551
  • 4
  • 41
  • 81
Charles Sungkono
  • 145
  • 2
  • 10

1 Answers1

2

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.

Jens Mühlenhoff
  • 14,565
  • 6
  • 56
  • 113
  • Jens, I have succeeded to use listview in virtual mode. I also have followed the instruction to add checkbox from link in my question and I still can't get the checkbox appear in the listview. Does the code from link above work for you? – Charles Sungkono Oct 27 '11 at 12:21
  • It "works" when you I set CheckBoxes to True and OwnerDraw to False. If you don't the VCL will draw over the CheckBoxes and you won't see them. – Jens Mühlenhoff Oct 27 '11 at 14:19
  • From link above, what is `FileListMenu` in `DrawCheckMark(FileListMenu.ListView1, Item, Item.Checked);`? I just put this in my code `DrawCheckMark(ListView1, Item, Item.Checked);`. Jens, I used to use TVirtualTree! but I am anticipating if I have to port my program to x64. Nobody guarantee TVirtualTree will be compatible with DXE2 x64. I make a simple demo that use code in link above, if you have another five minutes, please check. http://uploading.com/files/371emeb4/demo.zip/ – Charles Sungkono Oct 28 '11 at 02:07
  • Well the CheckBox is there, it is not drawn as checked. If you add `Item.Checked := True` to your `ListView1Data` it is drawn as Checked. So everything works as expected. – Jens Mühlenhoff Oct 28 '11 at 07:58
  • You can't change the CheckBox state by clicking on it though, if you want that behavior you'd have to write code for that yourself. – Jens Mühlenhoff Oct 28 '11 at 07:59
  • Aparently TVirtualTreevView is already being ported to XE2: http://code.google.com/p/virtual-treeview/source/list – Jens Mühlenhoff Oct 28 '11 at 08:02
  • Yeah they already ported it to XE2 for 32 bit version and I pray they will port it to 64 bit version :) I think I am going to switch back to use third party component for a while. – Charles Sungkono Oct 28 '11 at 13:16