Hi
Ich versuch mich in die VirtualTreeview einzuarbeiten, mein Problem ist, wie mache ich das mit den Pointer (wichtig!) in der Standard TreeView hast du ja Selected.Data
Ich möchte ne
DB in die VirtualTreeview einlesen und natürlich auch bearbeiten können
Synchron zur
DB
Kann mir da jemand weiterhelfen?
Hier ist ein wenig Code wie ich das vorher gemacht hatte
Delphi-Quellcode:
{******************************* Fill Group-List ******************************}
procedure TMain_Form.GroupList_Fill();
procedure FillTreeNode(TreeNode: TTreeNode);
var I, FolderID : Integer;
Node : TTreeNode;
Count : Integer;
GroupData : TGroupData;
begin
FolderID := Integer(TreeNode.Data); << Pointer
GroupTable.Filter:= 'ParentID=' + IntToStr(FolderID);
GroupTable.Filtered:= true;
GroupTable.First;
Count:= GroupTable.RecordCount;
for I := 0 to Count - 1 do
begin
Get_GroupData(GroupData);
Node := GroupTree.Items.AddChild(TreeNode, GroupData.Title);
Node.Data := Pointer(GroupTable.FieldByName('ID').AsLargeInt); << Pointer
Node.SelectedIndex:= GroupData.Icon;
Node.ImageIndex:= GroupData.Icon;
GroupTable.Next;
end;
for I := 0 to TreeNode.Count - 1 do
FillTreeNode(TreeNode.Item[I]);
end;
begin
GroupTree.Items.BeginUpdate;
GroupTree.Items.Clear;
with GroupTree.Items.Add(nil, 'My Data') do
begin
Data := Pointer(0);
ImageIndex := 0;
SelectedIndex := 0;
end;
FillTreeNode(GroupTree.Items[0]);
if GroupTree.Items.Count > 0 then
GroupTree.Items[0].Expanded:= true;
GroupTree.Items.EndUpdate;
GroupTree.Items[Temp_NodeIndex].Selected := True;
GroupTree.Items[Temp_NodeIndex].MakeVisible;
ValueList_Fill(Temp_FolderID);
SetNodeBoldState(GroupTree.Items[0], true);
end;
Delete
Delphi-Quellcode:
(******************************** Delete Group ********************************)
Function TMain_Form.Group_Delete(): Boolean;
function GetHeight(TreeNode: TTreeNode): Integer;
function MaxLevel(TreeNode: TTreeNode): Integer;
var i, level: Integer;
begin
Result := TreeNode.AbsoluteIndex;
if TreeNode.Count > 0 then
begin
for i := 0 to Pred(TreeNode.Count) do
begin
level := MaxLevel(TreeNode.Item[i]);
if Result < level then
Result := level;
end
end;
end;
begin
if Assigned(TreeNode) then
Result := MaxLevel(TreeNode) - TreeNode.AbsoluteIndex
else
Result := -1;
end;
var
FolderID, Res, I : Integer;
StartIdx, EndIdx : Integer;
TreeNode : TTreeNode;
begin
Result:= false;
if GroupTree.Selected = nil then
Exit;
TreeNode:= GroupTree.Selected;
if FConfirmOnDelFolder then
begin
Res:= ShowMSDlg(PWideChar(Format(ID_MSG_0020, [GroupTree.Selected.Text])), PWideChar(ID_MSG_0009), MB_ICONQUESTION or MB_YESNO);
// Res := ShowMSDlg(PChar('Are you sure you want to delete the folder " ' + GroupTree.Selected.Text + ' and all its content?'), 'Confirm deletion', MB_ICONQUESTION or MB_YESNO);
if Res = ID_NO then
Exit;
end;
if TreeNode.HasChildren then
begin
StartIdx:= GroupTree.Selected.AbsoluteIndex;
EndIdx:= GetHeight(TreeNode) + GroupTree.Selected.AbsoluteIndex;
for I := EndIdx downto StartIdx do
begin
FolderID := Integer(GroupTree.Items[i].Data); << Pointer
GroupTable.Filtered := False;
GroupTable.IndexName:= 'ID';
if GroupTable.FindKey([FolderID]) then
begin
GroupTable.Delete;
ValueTable.Filtered := False;
ValueTable.IndexName:= 'ByFolderID';
while ValueTable.FindKey([FolderID]) do
begin
ValueTable.Delete;
end;
GroupTree.Items[i].Delete;
end;
end;
end
else
begin
FolderID := Integer(TreeNode.Data); << Pointer
GroupTable.Filtered := False;
GroupTable.IndexName := 'ID';
if GroupTable.FindKey([FolderID]) then
begin
GroupTable.Delete;
ValueTable.Filtered := False;
ValueTable.IndexName:= 'ByFolderID';
while ValueTable.FindKey([FolderID]) do
begin
ValueTable.Delete
end;
TreeNode.Delete;
end;
end;
Result:= true;
end;