check treeview 节点赋值true 但没有打勾(100分)

  • 主题发起人 主题发起人 cp0574
  • 开始时间 开始时间
C

cp0574

Unregistered / Unconfirmed
GUEST, unregistred user!
我在form1 放置了一个 CheckTreeView1
在form1.onshow 事件中
CheckTreeView1.Items[1].Expand(true);
CheckTreeView1.SetChecked(CheckTreeView1.Items[2],true);
if CheckTreeView1.ischecked(CheckTreeView1.Items[2]) then

showmessage('111');
一运行就弹出消息框‘111’,但是CheckTreeView1.Items[2],并没有打勾,原因何在???
下面这个是我从网上找来的check treeview 源码

unit CheckTreeview;
interface
uses
Windows, Messages, SysUtils, Classes, Controls,Commctrl,ComCtrls;
const
TVIS_CHECKED = $2000;
type
TCheckTreeview = class(TTreeView)
private
{ Private declarations }
protected
{ Protected declarations }
procedure CreateParams(var Params: TCreateParams);
override;
public
{ Public declarations }
function IsChecked(Node :TTreeNode) :Boolean;
procedure SetChecked(Node :TTreeNode;
Checked :Boolean);
published
{ Published declarations }
end;

procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [TCheckTreeview]);
end;

{ TCheckTreeview }
procedure TCheckTreeview.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.Style:=Params.Style or TVS_CHECKBOXES;
end;

function TCheckTreeview.IsChecked(Node: TTreeNode): Boolean;
var
TvItem :TTVItem;
begin
TvItem.Mask := TVIF_STATE;
TvItem.hItem := Node.ItemId;
TreeView_GetItem(Node.TreeView.Handle, TvItem);
Result := (TvItem.State and TVIS_CHECKED) = TVIS_CHECKED;
end;

procedure TCheckTreeview.SetChecked(Node: TTreeNode;
Checked: Boolean);
var
TvItem :TTVItem;
begin
FillChar(TvItem, SizeOf(TvItem), 0);
with TvItemdo
begin
hItem := Node.ItemId;
Mask := TVIF_STATE;
StateMask := TVIS_STATEIMAGEMASK;
if Checked then
TvItem.State :=TVIS_CHECKED
else
TvItem.State :=TVIS_CHECKED shr 1;
TreeView_SetItem(Node.TreeView.Handle, TvItem);
end;
end;
end.
 
后退
顶部