VritualTreeView中如何展开子节点 。不明白。有代码,往高手解释... ( 积分: 200 )

  • 主题发起人 主题发起人 loshunter
  • 开始时间 开始时间
L

loshunter

Unregistered / Unconfirmed
GUEST, unregistred user!
我本意是通过代码把数据表的一个嵌套结构展开成树状,可是现在根节点可以划出。下面的节点都没有出来 。很奇怪 ,请高手指教...
贴出了定义部分,和 onInitChildren,OnInitNode,另外GetText没有贴出来,我觉得那部分没有问题。请大家帮忙。。谢....
type

PUserPermission = ^TUserPermission;
TUserPermission = record
Level: Integer;//Sender.GetNodeLevel(Node) 节点等级
LevelCode: String;
Node: PVirtualNode;
UserID: Integer;
ResourceID: Integer;
FormName: String;
TabSheetName: String;
FunctionName: String;
ResourceName: String;
Permission: Integer;
end;

procedure TfrmUserSet.cxButton1Click(Sender: TObject);
var
sdsPermission: TSQLDataSet;
index: Integer;
i: Integer;
PData: PUserPermission;
Node: PVirtualNode;
Run1, Run2: PVirtualNode;
begin
RoleCBKey;//与这个过程没有关系,就不贴了

try
sdsPermission := TSQLDataSet.Create(nil);

if sdsPermission is TSQLDataSet then
begin
sdsPermission.Close;
sdsPermission.CommandText :=
'SELECT * FROM vs_Permission WHERE sP_Role =' + '''' +
IntToStr(RoleKey) + '''' +' ORDER BY sP_resource';
sdsPermission.SQLConnection := dmmain.dbscnnMain;
if not sdsPermission.Prepared then
sdsPermission.Prepared := True;
sdsPermission.Open;
end;

vstPermission.RootNodeCount := 1;
vstPermission.NodeDataSize := SizeOf(TUserPermission);
Index := 0;

with sdsPermission do
begin
SetLength(FUserPermission, RecordCount - 1);
while not Eof do
begin
with FUserPermission[Index] do
begin
FormName := FieldByName('sRe_Form').AsString;
TabSheetName := FieldByName('sRe_TabSheet').AsString;
ResourceName := FieldByName('sRe_Description').AsString;
LevelCode := Trim(FieldByName('sRe_Code').AsString);
Level := Length(LevelCode) div 2;
end;
Inc(Index);
Next;
end;
end;

with vstPermission do
begin
BeginUpdate;
Clear;
RootNodeCount := 1;
NodeDataSize := SizeOf(TUserPermission);
EndUpdate;
end;

finally
sdsPermission.Free;
end;
end;

procedure TfrmUserSet.vstPermissionInitNode(Sender: TBaseVirtualTree;
ParentNode, Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
const
LevelToCheckType: array[0..5] of TCheckType = (
ctButton, ctRadioButton, ctTriStateCheckBox, ctTriStateCheckBox, ctCheckBox, ctNone
);
var
Data: PUserPermission;
index: Integer;
begin
Data := Sender.GetNodeData(Node);
Data^ := FUserPermission[Node.Index];
with Data^ do
begin
Level := Sender.GetNodeLevel(Node);
if Level < LevelCount then
begin
Include(InitialStates, ivsHasChildren);
if Level = 0 then
begin
Include(InitialStates, ivsExpanded);
end;
end;
end;

Sender.CheckState[Node] := csCheckedNormal;
end;

procedure TfrmUserSet.vstPermissionInitChildren(Sender: TBaseVirtualTree;
Node: PVirtualNode; var ChildCount: Cardinal);
var
Data: PUserPermission;
begin
Data := Sender.GetNodeData(Node);
if Data.Level < LevelCount then
ChildCount := 1;
end;
 
有个允许子节点的属性你看看.我现在没有安装这个控件.具体哪个我也不清楚了.
 
后退
顶部