Einzelnen Beitrag anzeigen

Hawkeye219

Registriert seit: 18. Feb 2006
Ort: Stolberg
2.227 Beiträge
 
Delphi 2010 Professional
 
#6

Re: Virtual Treeview MultiSelect/Onchange Event Problem

  Alt 6. Jul 2009, 10:24
Hallo DataCool,

hier ist ein Vorschlag zur Lösung deines Problems:

Delphi-Quellcode:
type
  TForm1 = class(TForm)
    [...]
  private
    OldSelection : TNodeArray;
    procedure HandleSelection (const aNode: PVirtualNode);
    procedure HandleDeselection (const aNode: PVirtualNode);
  end;

procedure TForm1.VSTChange (Sender: TBaseVirtualTree; Node: PVirtualNode);

  function _Contains (const aNodes: TNodeArray; const aNode: PVirtualNode): Boolean;
  var
    i : Integer;
  begin
    for i := 0 to High(aNodes) do
      if (aNodes[i] = aNode) then
        begin
          Result := True;
          Exit;
        end;

    Result := False;
 end;

var
  NewSelection : TNodeArray;
  i : Integer;
begin
  NewSelection := VST.GetSortedSelection(False);

  for i := 0 to High(OldSelection) do
    if (not _Contains(NewSelection, OldSelection[i])) then
      HandleDeselection (OldSelection[i]);

  for i := 0 to High(NewSelection) do
    if (not _Contains(OldSelection, NewSelection[i])) then
      HandleSelection (NewSelection[i]);

  OldSelection := Copy(NewSelection);
end;

procedure TForm1.HandleSelection (const aNode: PVirtualNode);
begin
  Memo.Lines.Add(VST.Text[aNode, -1] + ' selected');
end;

procedure TForm1.HandleDeselection (const aNode: PVirtualNode);
begin
  Memo.Lines.Add(VST.Text[aNode, -1] + ' deselected');
end;
Gruß Hawkeye
  Mit Zitat antworten Zitat