AVM

Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • AVM
    Participant
    'Stephane wrote:

    That works too.

    Code:
    procedure TForm1.FormShow(Sender: TObject);
    const
    TVS_NOHSCROLL = 32768;
    begin
    SetWindowLong( TreeView1.Handle, GWL_STYLE, GetWindowLong( TreeView1.Handle, GWL_STYLE ) or TVS_NOHSCROLL );
    TreeView1.Items.AddChild(nil, 'dlsahskjhagsdhfaksfjhsdkfjH');
    end;

    Благодарю, работает.

    AVM
    Participant
    'JackSon_by' wrote:

    Решение не самое элегантное, но я так отлавливаю:

    Code:
    procedure TForm1.sTreeViewEx1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    var dNode : TTreeNode;
    begin
    dNode := sTreeViewEx1.GetNodeAt(X, Y);

    if (Button = mbLeft) and (dNode nil) then
    begin

    ShowMessage( dNode.Text + ' = ' + BoolToStr(sTreeViewEx1.GetChecked(dNode), true) );

    end;

    end;

    Благодарю, работает.

    От себя выложу код, который исправляет правильную обработку свойств AutoChildCheck и AutoParentCheck (Их нужно выставить в False);

    Code:
    procedure TreeNodeCheck(Tree: TsTreeViewEx; Node: TTreeNode; Checked: Boolean);
    var
    pNode : TTreeNode;
    function SetChildChecked(Tree:TsTreeViewEx; pNode: TTreeNode; Checked: Boolean): Integer;
    var i,r: Integer;
    begin
    r := 0;
    for i := 0 to PNode.Count – 1 do
    begin
    Tree.SetChecked(Pnode.Item,Checked);
    Inc(r);
    Inc(r, SetChildChecked(Tree,Pnode.Item,Checked));
    end;
    Result := r;
    end;
    function CheckChildStatus(Tree:TsTreeViewEx; pNode: TTreeNode): Boolean;
    var i,r: Integer;
    begin
    Result := False;
    for i := 0 to PNode.Count – 1 do
    begin
    if Tree.GetChecked(pNode) then
    begin
    Result := True;
    Exit;
    end;
    Result := CheckChildStatus(Tree,pnode);
    if Result then
    Exit;
    end;
    end;
    begin
    if (Node nil) then
    begin
    //Отмечаем потомков
    SetChildChecked(Tree,Node,Checked);
    //Отмечаем предков
    pNode := Node.Parent;
    while pNode nil do
    begin
    Tree.SetChecked(pNode,CheckChildStatus(Tree,pNode));
    pNode := pNode.Parent;
    end;
    end;
    end;

    procedure TFMain.trTreeMouseDown(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
    var
    Node : TTreeNode;
    Checked: Boolean;
    begin
    Node := TsTreeViewEx(Sender).GetNodeAt(X, Y);
    if (Button = mbLeft) and (Node nil) then
    begin
    Checked := TsTreeViewEx(Sender).GetChecked(Node);
    TreeNodeCheck(TsTreeViewEx(Sender),Node,Checked);
    //Передаем событие в OnClick, если надо
    if Assigned(TsTreeViewEx(Sender).OnClick) then
    TsTreeViewEx(Sender).OnClick(Sender);
    end;
    end;

Viewing 2 posts - 1 through 2 (of 2 total)