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

 Delphi Discussion :

Items sur plusieurs lignes


Sujet :

Delphi

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Février 2008
    Messages
    108
    Détails du profil
    Informations personnelles :
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Février 2008
    Messages : 108
    Points : 61
    Points
    61
    Par défaut Items sur plusieurs lignes
    Bonjour,

    Pour mon application, je charge les Items d'une Listbox via un fichier INI.
    J'aimerais savoir, s'il est possible d'avoir des retours chariot dans une TListbox, car certains Items (incompressibles) sont très longs, ce qui nécessite d'avoir une largeur de Listbox trop importante pour pouvoir afficher le texte en entier.

    Merci pour vos réponses.

  2. #2
    Expert éminent sénior
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    13 654
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 13 654
    Points : 25 417
    Points
    25 417
    Par défaut
    A mon avis, tu dois jouer avec ItemHeight, Style à lbOwnerDraw et OnDrawItem et appeler Windows.DrawText avec DT_WORDBREAK

    Tu dois avoir des sujets dans le forum, et peut-être même un exemple dans la FAQ

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Février 2008
    Messages
    108
    Détails du profil
    Informations personnelles :
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Février 2008
    Messages : 108
    Points : 61
    Points
    61
    Par défaut
    Merci pour ta réponse Shai Le Troll.

    J'ai bien regardé sur la FAq est je n'ai touvé que cele :

    http://delphi.developpez.com/faq/?pa...tdansstringrid

    Je ne sais pas si cela est adaptable à un listbox.

    D'autre part, dans mon application, j'ai plusieurs Listbox dans lesquelles je fais mes choix.

    Tous les choix sont regroupés dans un Listbox (récapitulative). J'ai placé sur mes Listbox des boutons d'ajout et de retrait. Mon problème est que quand je fais mes choix dans plusieurs Listbox et que je veux retirer un choix de la listbox récapitulative, ce choix se place dans la Listobx1, alors qu'il peut être issu de la Listbox3 par exemple.

    Y a-t-il un moyen de remédier à cela?

    Voici mon code :

    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
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
     
    unit competances;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Classes, Graphics, Forms, Dialogs, Controls, StdCtrls,
      Buttons, ComCtrls;
     
     P1lireSub1: TListBox;
        IncludeBtn: TSpeedButton;
        IncAllBtn: TSpeedButton;
        ExcludeBtn: TSpeedButton;
        ExAllBtn: TSpeedButton;
        P1LireSub2: TListBox;
        Listcomp: TListBox;
        SpeedButton1: TSpeedButton;
        P1LireSub3: TListBox;
        P1LireSub4: TListBox;
        P1LireSub5: TListBox;
        SpeedButton2: TSpeedButton;
        SpeedButton3: TSpeedButton;
        SpeedButton4: TSpeedButton;
        procedure IncludeBtnClick(Sender: TObject);
        procedure ExcludeBtnClick(Sender: TObject);
        procedure IncAllBtnClick(Sender: TObject);
        procedure ExcAllBtnClick(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure SpeedButton1Click(Sender: TObject);
        procedure SpeedButton2Click(Sender: TObject);
        procedure SpeedButton3Click(Sender: TObject);
        procedure SpeedButton4Click(Sender: TObject);
        procedure P1LireSub3DrawItem(Control: TWinControl; Index: Integer;
          Rect: TRect; State: TOwnerDrawState);
      private
        { Déclarations privées }
      public
        { Déclarations publiques }
        procedure MoveSelected(List: TCustomListBox; Items: TStrings);
        procedure SetItem(List: TListBox; Index: Integer);
        function GetFirstSelection(List: TCustomListBox): Integer;
        procedure SetButtons;
      end;
     
    var
      DualListDlg: TDualListDlg;
     
    implementation
     
    {$R *.dfm}
     
    procedure TDualListDlg.IncludeBtnClick(Sender: TObject);
    var
      Index: Integer;
    begin
      Index := GetFirstSelection(P1LireSub1);
      MoveSelected(P1LireSub1, ListComp.Items);
      SetItem(P1LireSub1, Index);
    end;
     
    procedure TDualListDlg.ExcludeBtnClick(Sender: TObject);
    var
      Index: Integer;
    begin
      Index := GetFirstSelection(ListComp);
      MoveSelected(ListComp, P1LireSub1.Items);
      SetItem(ListComp, Index);
    end;
     
    procedure TDualListDlg.FormCreate(Sender: TObject);
    begin
    P1LireSub1.Items.LoadFromFile ('c:\logival\compétances\P1LireSub1.ini');
    P1LireSub2.Items.LoadFromFile('c:\logival\compétances\P1LireSub2.ini') ;
    P1LireSub3.Items.LoadFromFile('c:\logival\compétances\P1LireSub3.ini') ;
    P1LireSub4.Items.LoadFromFile('c:\logival\compétances\P1LireSub4.ini') ;
    P1LireSub5.Items.LoadFromFile('c:\logival\compétances\P1LireSub5.ini') ;
     
    end;
     
    procedure TDualListDlg.IncAllBtnClick(Sender: TObject);
    var
      I: Integer;
    begin
      for I := 0 to P1LireSub1.Items.Count - 1 do
        ListComp.Items.AddObject(P1LireSub1.Items[I],
          P1LireSub1.Items.Objects[I]);
      P1LireSub1.Items.Clear;
      SetItem(P1LireSub1, 0);
    end;
     
     
    procedure TDualListDlg.ExcAllBtnClick(Sender: TObject);
    var
      I: Integer;
    begin
      for I := 0 to ListComp.Items.Count - 1 do
        P1LireSub1.Items.AddObject(ListComp.Items[I], ListComp.Items.Objects[I]);
      ListComp.Items.Clear;
      SetItem(P1LireSub1, 0);
    end;
     
    procedure TDualListDlg.MoveSelected(List: TCustomListBox; Items: TStrings);
    var
      I: Integer;
    begin
      for I := List.Items.Count - 1 downto 0 do
        if List.Selected[I] then
        begin
          Items.AddObject(List.Items[I], List.Items.Objects[I]);
          List.Items.Delete(I);
        end;
    end;
     
    procedure TDualListDlg.P1LireSub3DrawItem( Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    begin
     
        { Dessin du texte en utilisant la fonction API }
        DrawText(Canvas.Handle, PChar(P1LireSUB3.Items), -1, Rect ,DT_NOPREFIX or DT_WORDBREAK );
      end;
     
     
     
     
    procedure TDualListDlg.SpeedButton1Click(Sender: TObject);
    var
      Index: Integer;
    begin
      Index := GetFirstSelection(P1LireSub2);
      MoveSelected(P1LireSub2, ListComp.Items);
      SetItem(P1LireSub2, 0);
    end;
     
    procedure TDualListDlg.SpeedButton2Click(Sender: TObject);
    var
      I: Integer;
    begin
      for I := 0 to P1LireSub2.Items.Count - 1 do
        ListComp.Items.AddObject(P1LireSub2.Items[I],
          P1LireSub2.Items.Objects[I]);
      P1LireSub2.Items.Clear;
      SetItem(P1LireSub2, 0);
     
    end;
     
    procedure TDualListDlg.SpeedButton3Click(Sender: TObject);
    var
      Index: Integer;
    begin
      Index := GetFirstSelection(ListComp);
      MoveSelected(ListComp, P1LireSub2.Items);
      SetItem(ListComp, Index);
     
    end;
     
    procedure TDualListDlg.SpeedButton4Click(Sender: TObject);
    var
      I: Integer;
    begin
      for I := 0 to ListComp.Items.Count - 1 do
        P1LireSub2.Items.AddObject(ListComp.Items[I], ListComp.Items.Objects[I]);
      ListComp.Items.Clear;
      SetItem(P1LireSub2, 0);
    end;
     
    procedure TDualListDlg.SetButtons;
    var
      P1LireSub1Empty, DstEmpty, P1LireSub2Empty: Boolean;
    begin
      P1LireSub1Empty := P1LireSub1.Items.Count = 0;
        DstEmpty := ListComp.Items.Count = 0;
      P1LireSub1Empty := P1LireSub2.Items.Count = 0;
      Speedbutton1.Enabled := not P1LireSub1empty;
      Speedbutton3.Enabled := not P1LireSub1empty;
      IncludeBtn.Enabled := not P1LireSub1Empty;
      IncAllBtn.Enabled := not P1LireSub1Empty;
      ExcludeBtn.Enabled := not DstEmpty;
      ExAllBtn.Enabled := not DstEmpty;
    end;
     
    {function TDualListDlg.GetFirstSelection0(List: TCustomListBox): Integer;
    begin
      for Result := 0 to List.Items.Count -1  do
        if List.Selected[Result] then Exit;
      Result := LB_ERR;
    end;       }
     
    function TDualListDlg.GetFirstSelection(List: TCustomListBox): Integer;
    begin
      for Result := 0 to List.Items.Count-1  do
        if List.Selected[Result] then Exit;
      Result := LB_ERR;
    end;
     
    procedure TDualListDlg.SetItem(List: TListBox; Index: Integer);
    var
      MaxIndex: Integer;
    begin
      with List do
      begin
        SetFocus;
        MaxIndex := List.Items.Count - 1;
        if Index = LB_ERR then Index := 0
        else if Index > MaxIndex then Index := MaxIndex;
        Selected[Index] := True;
      end;
      SetButtons;
    end;
     
     
     
    end.

  4. #4
    Expert éminent sénior
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    13 654
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 13 654
    Points : 25 417
    Points
    25 417
    Par défaut
    Utiliser la propriété Objects des items que tu passe d'une ListBox à l'autre (utilise AddObject au lieu de Add) et dans cet objet tu indique des informations comme la provenance de la Strings ... tu peux utiliser Object comme un Entier par Transtypage ou faire une vraie gestion avec des Objets (Création, libération, ...)

  5. #5
    Membre émérite Avatar de edam
    Homme Profil pro
    Développeur Delphi/c++/Omnis
    Inscrit en
    Décembre 2003
    Messages
    1 894
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur Delphi/c++/Omnis
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 1 894
    Points : 2 771
    Points
    2 771
    Par défaut
    quelque suggestion:
    tu utilise un simple listBox, pas un checklistbox:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    procedure TDualListDlg.MoveSelected(List: TCustomListBox; Items: TStrings);
    var
      I: Integer;
    begin
          i:=List.ItemIndex;
          Items.AddObject(List.Items[i], List.Items.Objects[i]);
          List.Items.Delete(I);
    end;
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    procedure TDualListDlg.SpeedButton2Click(Sender: TObject);
    var
      I: Integer;
    begin
      ListComp.Items.AddStrings(P1LireSub2.Items);
      P1LireSub2.Items.Clear;
      SetItem(P1LireSub2, 0);
    end;
    pourquoi utilisé des fichier ini? une BD sera plus recommandé, non?

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-MAC 2011] Listbox : 1 item sur plusieurs lignes
    Par lezbleu34 dans le forum Excel
    Réponses: 0
    Dernier message: 22/04/2014, 17h06
  2. Réponses: 3
    Dernier message: 13/05/2011, 10h54
  3. Item de Liste <LI> sur plusieurs lignes
    Par kabkab dans le forum Mise en page CSS
    Réponses: 1
    Dernier message: 23/05/2008, 16h45
  4. [VB.NET] Repeater plusieurs items sur une ligne
    Par diaboloche dans le forum ASP.NET
    Réponses: 5
    Dernier message: 09/03/2007, 13h53
  5. Define sur plusieurs lignes
    Par Gogoye dans le forum C
    Réponses: 6
    Dernier message: 06/10/2003, 11h45

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