Discussion:
TListView; disable an item
(too old to reply)
Agostino
2004-01-22 15:12:31 UTC
Permalink
I've a TListView that has checkbox set to true, then I fill it with items.
I would like to 'disable' some of them, so that they can be checked.
I can't find a way to achieve this, perhaps there is a trick to do this.

Thanks in advance
Agostino
Agostino
2004-01-22 16:34:49 UTC
Permalink
Post by Agostino
I've a TListView that has checkbox set to true, then I fill it with items.
"checkboxes" property
Post by Agostino
I would like to 'disable' some of them, so that they can be checked.
so that they can't be checked

Thanks
Post by Agostino
I've a TListView that has checkbox set to true, then I fill it with items.
I would like to 'disable' some of them, so that they can be checked.
I can't find a way to achieve this, perhaps there is a trick to do this.
Thanks in advance
Agostino
Peter Below (TeamB)
2004-01-22 19:30:55 UTC
Permalink
Post by Agostino
I've a TListView that has checkbox set to true, then I fill it with items.
I would like to 'disable' some of them, so that they can be checked.
I can't find a way to achieve this, perhaps there is a trick to do this.
Since the control has no support for disabled items you have to dive down to
the API layer and watch for mouse messages coming through (subclass the
control via its WindowProc property, or make a descendent and override
WndProc). You can use the GetHitTestInfoAt and GetItemAt methods to figure
out where the mouse click is going to land, if its on a disabled item you
simply do not pass the message on to the replaced window proc.

--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
Constantine Yannakopoulos
2004-01-23 09:26:07 UTC
Permalink
Author := "Peter Below (TeamB)";

| Since the control has no support for disabled items you have to dive
| down to the API layer and watch for mouse messages coming through
| (subclass the control via its WindowProc property, or make a
| descendent and override WndProc). You can use the GetHitTestInfoAt
| and GetItemAt methods to figure out where the mouse click is going to
| land, if its on a disabled item you simply do not pass the message on
| to the replaced window proc.

An easier solution is to write an OnChange event handler that always
unchecks items if they are "disabled":

procedure TForm1.ListView1Change(Sender: TObject; Item: TListItem;
Change: TItemChange);
begin
if (Change = ctState) and not Enabled(Item) and Item.Checked then
Item.Checked := False;
end;
--
Constantine
Florent Ouchet
2004-01-23 12:15:42 UTC
Permalink
A checked item can also be disabled. So the change event become :

procedure TForm1.ListView1Change(Sender: TObject; Item: TListItem;
Change: TItemChange);
begin
if (Change = ctState) and not Enabled(Item) then
Item.Checked := not Item.Checked;
end;

An other suggestion : why you don't use the TCheckListBox which have a
"State" property (Checked, Uncheked or grayed) and a ItemEnabled property
for each item.

Florent
Post by Constantine Yannakopoulos
Author := "Peter Below (TeamB)";
| Since the control has no support for disabled items you have to dive
| down to the API layer and watch for mouse messages coming through
| (subclass the control via its WindowProc property, or make a
| descendent and override WndProc). You can use the GetHitTestInfoAt
| and GetItemAt methods to figure out where the mouse click is going to
| land, if its on a disabled item you simply do not pass the message on
| to the replaced window proc.
An easier solution is to write an OnChange event handler that always
procedure TForm1.ListView1Change(Sender: TObject; Item: TListItem;
Change: TItemChange);
begin
if (Change = ctState) and not Enabled(Item) and Item.Checked then
Item.Checked := False;
end;
--
Constantine
Loading...