Re:Adding Items to TreeView
Quote
In article <8qtdhg$ct...@bornews.borland.com>, Jay Jackson wrote:
> * Role
> | --- Screen
> | --- [x] Object
> I have set of a while loop that iterates through the table, but I cannot
> figure out how to add the nodes without duplicating levels and how to add
> the checkbox values.
You need to maintain references to the last node witten at each level and
write new ones as required. You should be able to adapt the rough
approximate code below to something that works for you:
const ints: array[boolean] of integer = (1,2);
var roleNode,screenNode,objectNode: TTreeNode;
var sRole,sScreen,sObject: string;
roleNode := nil;
screenNode := nil;
TreeView1.Items.BeginUpdate;
try
while not Query1.EOF do begin
sRole := Query1.FieldByName('Role').AsString;
sScreen := Query1.FieldByName('Screen').AsString;
sObject := Query1.FieldByName('Object').AsString;
if (roleNode=nil) or (roleNode.Text <> sRole) then
roleNode := TreeView1.Items.AddChild(nil,sRole);
if (screenNode=nil) or (screenNode.Text <> sScreen) then
screenNode := TreeView1.Items.AddChild(roleNode,sScreen);
end;
objectNode := TreeView1.Items.AddChild(screenNode,sObject);
objectNode.StateIndex :=
ints[Query1.FieldByName('Access').AsBoolean]; // see below
Query1.Next;
end;
finally
TreeView1.Items.EndUpdate;
end;
You will note the reference to StateIndex above. Drop an ImageList on to
the form and set the TreeView1.StateImages property. If you now add images
to the ImageList so that the second and third items show an unchecked box
and a checked box, you get the purpose.
Mike Orriss (TeamB & Developer Express)
(Unless stated otherwise, my replies relate to Delphi 5)
(No unsolicited e-mail replies please)