IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants VCL Delphi Discussion :

TreeView expand en un seul click (question pointue ;)


Sujet :

Composants VCL Delphi

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    63
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 63
    Points : 40
    Points
    40
    Par défaut TreeView expand en un seul click (question pointue ;)
    Bonjour,

    Question à 100 €

    Je voudrais que mon treeview puisse developper une branche mais en un seul click, au lieu du double click.

    Il y a bien la propriété autoexpand qui developpe une branche en seul click mais elle réduit en même temps toutes les autres blanches deveoppées. Elle fait en fait en un click expand sur la branche sélectionnée et collapse sur les autres banchres.

    J'ai regardé le source du treeview, en fait l'auoexpand est obtenu par setwindowlong

    > SetWindowLong(TreeView1.Handle, GWL_STYLE, TVS_SINGLEEXPAND);

    N'y a t'il pas un moyen de provoquer seulement l'expand en seul click sans réduire les autres branches ouvertes.

    Merci

  2. #2
    Membre expérimenté Avatar de guillemouze
    Profil pro
    Inscrit en
    Novembre 2004
    Messages
    876
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Novembre 2004
    Messages : 876
    Points : 1 448
    Points
    1 448
    Par défaut
    je pense que tu peux t'en sortir en mettant, sur le onExpand, le expandAll sur le noeud en question

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    63
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 63
    Points : 40
    Points
    40
    Par défaut
    Ayé j'ai la soluce effectivement je fesais fausse route


    Il faut d'abord créer un compo dérivé d'un treeview puis désactivé le double click (j'ai pris le code a ebastien ici : http://www.developpez.net/forums/d29...t-double-clic/)

    Ensuite j'ai complété son code en surchargeant "click" pour développer (expand) ou réduire (collapse) la branche sélectionnée, au final ca donne :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    unit MyTreeView;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Classes, Controls, ComCtrls, CommCtrl;
     
    type
      TMyTreeView = class(TcustomtreeView)
      private
        fCanExpand : Boolean;
        fDblClicEnabled: Boolean;
        Procedure SetDblClicEnabled(Value : Boolean);
        procedure CNNotify(var Message: TWMNotify); message CN_NOTIFY;
        procedure WMLButtonDblClk(var Message: TWMLButtonDblClk); message WM_LBUTTONDBLCLK;
      Protected
        Procedure Click;Override;// On surcharge click pour expand et collapse la branche sélectionnée
      public
        constructor Create(AOwner: TComponent); override;
      published
        property Align;
        property Anchors;
        property AutoExpand;
        property BevelEdges;
        property BevelInner;
        property BevelOuter;
        property BevelKind default bkNone;
        property BevelWidth;
        property BiDiMode;
        property BorderStyle;
        property BorderWidth;
        property ChangeDelay;
        property Color;
        property Ctl3D;
        property Constraints;
        // Permet de bloquer le double clic 
        property DblClicEnabled : Boolean read fDblClicEnabled write SetDblClicEnabled;
    fDblClicEnabled;
        property DragKind;
        property DragCursor;
        property DragMode;
        property Enabled;
        property Font;
        property HideSelection;
        property HotTrack;
        property Images;
        property Indent;
        property MultiSelect;
        property MultiSelectStyle;
        property ParentBiDiMode;
        property ParentColor default False;
        property ParentCtl3D;
        property ParentFont;
        property ParentShowHint;
        property PopupMenu;
        property ReadOnly;
        property RightClickSelect;
        property RowSelect;
        property ShowButtons;
        property ShowHint;
        property ShowLines;
        property ShowRoot;
        property SortType;
        property StateImages;
        property TabOrder;
        property TabStop default True;
        property ToolTips;
        property Visible;
        property OnAddition;
        property OnAdvancedCustomDraw;
        property OnAdvancedCustomDrawItem;
        property OnChange;
        property OnChanging;
        property OnClick;
        property OnCollapsed;
        property OnCollapsing;
        property OnCompare;
        property OnContextPopup;
        property OnCreateNodeClass;
        property OnCustomDraw;
        property OnCustomDrawItem;
        property OnDblClick;
        property OnDeletion;
        property OnDragDrop;
        property OnDragOver;
        property OnEdited;
        property OnEditing;
        property OnEndDock;
        property OnEndDrag;
        property OnEnter;
        property OnExit;
        property OnExpanding;
        property OnExpanded;
        property OnGetImageIndex;
        property OnGetSelectedIndex;
        property OnKeyDown;
        property OnKeyPress;
        property OnKeyUp;
        property OnMouseDown;
        property OnMouseMove;
        property OnMouseUp;
        property OnStartDock;
        property OnStartDrag;
        { Items must be published after OnGetImageIndex and OnGetSelectedIndex }
        property Items;
     
      end;
     
    procedure Register;
     
    implementation
     
    procedure Register;
    begin
      RegisterComponents('eb', [TMyTreeView]);
    end;
     
    { TMyTreeView }
     
    constructor TMyTreeView.Create(AOwner: TComponent);
    begin
      inherited;
      fCanExpand := True;
      fDblClicEnabled := True;
    end;
     
    procedure TMyTreeView.CNNotify(var Message: TWMNotify);
    begin
      case Message.NMHdr^.code of
         TVN_ITEMEXPANDING:
         begin
           if not(fCanExpand) then
           begin
             Message.Result := 1;  // Blocage du Collapse/Expand
             fCanExpand := True;
           end;
         end;
      end;
      inherited;
    end;
     
    procedure TMyTreeView.WMLButtonDblClk(var Message: TWMLButtonDblClk);
    begin
      if not(fDblClicEnabled) then
        fCanExpand := False;
      inherited;
    end;
     
    Procedure TMyTreeView.Click;
    Begin
      Inherited Click;
      If not(fDblClicEnabled) then If self.Selected.Expanded then self.Selected.Collapse(false) else self.Selected.Expand(false);
    End;
     
    Procedure TMyTreeView.SetDblClicEnabled(Value : Boolean);
    Begin
      FDblClicEnabled := Value;
      If FDblClicEnabled=false then
      Begin
      ReadOnly:=True;// Le fonctionnement "un seul click" est incompatible avec l'édition du label
      AutoExpand:=False;// Le fonctionnement "un seul click" est incompatible avec AutoExpand
      End;
    End;
     
     
    end.

  4. #4
    Expert confirmé
    Avatar de popo
    Homme Profil pro
    Analyste programmeur Delphi / C#
    Inscrit en
    Mars 2005
    Messages
    2 674
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Analyste programmeur Delphi / C#
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 2 674
    Points : 5 259
    Points
    5 259
    Par défaut
    Je pense qu'il y a plus simple.

    A verifier mais s'il existe TVS_SINGLEEXPAND il doit exister en exister un autre du genre TVS_ALLEXPAND.

Discussions similaires

  1. [C#] [TreeView] [contextMenu] selection sur un click droit
    Par weejungle dans le forum Windows Forms
    Réponses: 25
    Dernier message: 03/08/2009, 11h52
  2. [VB.net][treeview] Sélectionner un Node via click droit
    Par arnolem dans le forum Windows Forms
    Réponses: 3
    Dernier message: 22/03/2006, 11h45
  3. Réponses: 4
    Dernier message: 13/02/2006, 11h11
  4. [VB.NET][Treeview] lancer ItemDrag, meme si click en dehors du bound
    Par Harry_polin dans le forum Windows Forms
    Réponses: 5
    Dernier message: 13/01/2006, 22h21
  5. [VB.NET] [TreeView] expand node d'un treeview
    Par graphicsxp dans le forum Windows Forms
    Réponses: 3
    Dernier message: 07/04/2005, 16h21

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo