Board index » delphi » TListView Checkboxes Don't Work

TListView Checkboxes Don't Work

Whats the best fix for the D4 ListView Checkboxes?

I use the following to get around the bug (Checks don't work).
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;

 

Re:TListView Checkboxes Don't Work


Rob --

What do you mean when you say they don't work?  You provide a fix for
a problem that you don't describe.

Nick Hodges
TeamB

Re:TListView Checkboxes Don't Work


Quote
Nick Hodges (TeamB) wrote in message

<3639fd66.69734...@forums.inprise.com>...

Quote
>Rob --

>What do you mean when you say they don't work?  You provide a fix for
>a problem that you don't describe.

>Nick Hodges
>TeamB

By no working I mean... When you set them programatically
eg. LV.Items[3].Checked := TRUE;  Nothing happens.

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

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:TListView Checkboxes Don't Work


Rob  --

I think it was I who reported that bug. <g>

It seems to be working fine with Update #2.  Can you post a small,
simple code example that illustrates the problem?

Nick Hodges
TeamB

Re:TListView Checkboxes Don't Work


Quote
Nick Hodges (TeamB) wrote in message

<363dde1f.15981...@forums.inprise.com>...

Quote
>Rob  --

>I think it was I who reported that bug. <g>

>It seems to be working fine with Update #2.  Can you post a small,
>simple code example that illustrates the problem?

>Nick Hodges
>TeamB

Is there an update 2 now? I'll give that a go.

The example is simple. In say form create do

for n := 0 to ListView.Items.count-1 do
   ListView.Items[n].checked := true

The result is the last item only is checked.

Cheers
Robert

Re:TListView Checkboxes Don't Work


Rob --

Sorry it took so long to get back to you --

Yes, the code you posted works fine in the Update #2 -- did you get it
and try it out?

Nick Hodges
TeamB

Re:TListView Checkboxes Don't Work


Thanks Nick. Yes I just confirmed that... Update #2 has fix the checkboxes
for ListViews.

Quote
Nick Hodges (TeamB) wrote in message

<36474e92.24434...@forums.inprise.com>...
Quote
>Rob --

>Sorry it took so long to get back to you --

>Yes, the code you posted works fine in the Update #2 -- did you get it
>and try it out?

>Nick Hodges
>TeamB

Other Threads