Board index » delphi » D4: TListView Checkboxes Don't Work

D4: TListView Checkboxes Don't Work

Whats the best fix for the D4 ListView Checkboxes?

I use the following to get around the bug.
However, I would like to understand what the bug is and why my hack fixes
the problem?

procedure SetLVCheck(LV: TListView; idx: Integer; Value: Boolean);
var Styles: DWORD;
begin
  if LV.CheckBoxes = TRUE then LV.CheckBoxes := FALSE;
  Styles :=
Commctrl.ListView_GetExtendedListViewStyle(LV.Items[idx].Handle);
  Commctrl.ListView_SetExtendedListViewStyle(LV.Handle, Styles or
LVS_EX_CHECKBOXES);
  Commctrl.ListView_SetCheckState(LV.Handle, idx, Value);
end;

function GetLVCheck(LV: TListView; idx: Integer): Boolean;
begin
  if LV.CheckBoxes = TRUE then LV.CheckBoxes := FALSE;
  result := Commctrl.ListView_GetCheckState(LV.Items[idx].Handle, Idx) <> 0;
end;

---------------------

The above works. Using   ListView.Items[idx].Checked  does not!

Cheers
Robert

========================================================
NOTE: The problem has been reported...

http://www.inprise.com/devsupport/delphi/fixes/delphi4/vcl.html#standard
controls\tlistbox
Area: vcl\win 32 controls\tlistview
Reference Number: 328 (Published: 10/22/98)

Status: Open
Date Reported: 7/6/98
Severity: Commonly Encountered
Type: Basic Functionality Failure
Problem:

The Checked property of TListItem doesn't work
properly when adding list items. If a set of items is
added and the Checked property is set to true, only
the last item ends up checked.

 

Re:D4: TListView Checkboxes Don't Work


This is not exactly the same thread, but I thought it suited being posted
here.

When I swap two items in a CheckListBox, the checked flags are destroyed
(not a major problem), but Is this the defined behavior ?

Re:D4: TListView Checkboxes Don't Work


Don't know.  I think I found the same thing.
Quote
Paul Chapman wrote in message <71rr55$d...@forums.borland.com>...
>This is not exactly the same thread, but I thought it suited being posted
>here.

>When I swap two items in a CheckListBox, the checked flags are destroyed
>(not a major problem), but Is this the defined behavior ?

Other Threads