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 :

ajouter des combobox dans les cellules de stringgrid


Sujet :

Delphi

  1. #1
    Débutant  
    Inscrit en
    Mars 2008
    Messages
    1 123
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 1 123
    Points : 170
    Points
    170
    Par défaut ajouter des combobox dans les cellules de stringgrid
    comment ajouter des combobox dans les cellules de stringgrid
    j'ai trouvé des codes prêts mais j'ai pas compris comment ça marche
    merci

  2. #2
    Expert confirmé
    Avatar de popo
    Homme Profil pro
    Analyste programmeur Delphi / C#
    Inscrit en
    Mars 2005
    Messages
    2 730
    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 730
    Points : 5 391
    Points
    5 391
    Par défaut
    Dans ce cas tu pourrait poster ce code pour qu'on te l'explique

  3. #3
    Débutant  
    Inscrit en
    Mars 2008
    Messages
    1 123
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 1 123
    Points : 170
    Points
    170

  4. #4
    Membre expérimenté
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 450
    Détails du profil
    Informations personnelles :
    Âge : 71
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 450
    Points : 1 336
    Points
    1 336
    Par défaut Eh oui !
    @ Sky88, avec le lien que tu as communiqué, la 1ère unité est celle qui te permet de construire un composant, la seconde, c'est l'utilisation avec ce composant.

    Il y a plus simple sans composant spécial :

    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
     
    unit Unit1;
     
    interface
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Grids;
    type
      TForm1 = class(TForm)
        StringGrid1: TStringGrid;
        procedure StringGrid1SelectCell(Sender: TObject; Col, Row: Integer;
          var CanSelect: Boolean);
        procedure FormShow(Sender: TObject);
        procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
      private
        { Déclarations privées }
      public
        { Déclarations publiques }
        procedure ComboBox1Exit(Sender: TObject);
      end;
    var
      Form1: TForm1;
      ComboBox1:TComboBox;
     
    implementation
     
    {$R *.dfm}
     
    procedure TForm1.ComboBox1Exit(Sender: TObject);
    begin
         StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row]:=ComboBox1.Text;
         ComboBox1.Visible := False;
         StringGrid1.SetFocus;
    end;
     
    procedure TForm1.StringGrid1SelectCell(Sender: TObject;Col,Row: Integer; var CanSelect: Boolean);
    var
       R: TRect;
    begin
         if (Col > 0)
         and (Row <> 0)
         then begin
              R := StringGrid1.CellRect(Col, Row);
              R.Left := R.Left + StringGrid1.Left;
              R.Right := R.Right + StringGrid1.Left;
              R.Top := R.Top + StringGrid1.Top;
              R.Bottom := R.Bottom + StringGrid1.Top;
              ComboBox1.Left := R.Left + 1;
              ComboBox1.Top := R.Top + 1;
              ComboBox1.Width := (R.Right + 1) - R.Left;
              ComboBox1.Height := (R.Bottom + 1) - R.Top;
              ComboBox1.Visible := True;
              if StringGrid1.Cells[Col,Row]<>''
              then ComboBox1.Text:=StringGrid1.Cells[Col,Row]
              else ComboBox1.Text:='';
              ComboBox1.SetFocus;
         end;
         CanSelect := True;
    end;
     
    procedure TForm1.FormShow(Sender: TObject);
    Var
       X:Integer;
    begin
         StringGrid1.Options:=StringGrid1.Options+[goColSizing,goThumbTracking]-[goEditing];
         ComboBox1:=TComboBox.Create(Self);
         ComboBox1.Parent:=Form1;
         ComboBox1.Visible:=False;
         ComboBox1.OnExit:=ComboBox1Exit;
         ComboBox1.Clear;
         For X:=1 to 10
         do ComboBox1.Items.Add(IntToStr(X));
    end;
     
    procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
         ComboBox1.Free;
    end;
    end.
    Au fait, n'oublies pas aussi de fournir la version de Delphi quand tu demandes de l'aide.

    @+,

    Cincap

  5. #5
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 763
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 763
    Points : 13 381
    Points
    13 381
    Par défaut
    Petite simplification pour le positionnement du Combo.

    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
    procedure TForm1.StringGrid1SelectCell(Sender: TObject;Col,Row: Integer; var CanSelect: Boolean);
    var
       R: TRect;
    begin
         if (Col > 0)
         and (Row <> 0)
         then begin
              R := StringGrid1.CellRect(Col, Row);
              ComboBox1.BoundsRect := R;
              ComboBox1.Visible := True;
              if StringGrid1.Cells[Col,Row]<>''
              then ComboBox1.Text:=StringGrid1.Cells[Col,Row]
              else ComboBox1.Text:='';
              ComboBox1.SetFocus;
         end;
         CanSelect := True;
    end;
     
    procedure TForm1.FormShow(Sender: TObject);
    Var
       X:Integer;
    begin
         StringGrid1.Options:=StringGrid1.Options+[goColSizing,goThumbTracking]-[goEditing];
         ComboBox1:=TComboBox.Create(Self);
         ComboBox1.Parent:=StringGrid1;
         ComboBox1.Visible:=False;
         ComboBox1.OnExit:=ComboBox1Exit;
         ComboBox1.Clear;
         For X:=1 to 10
         do ComboBox1.Items.Add(IntToStr(X));
    end;

  6. #6
    Membre expérimenté
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 450
    Détails du profil
    Informations personnelles :
    Âge : 71
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 450
    Points : 1 336
    Points
    1 336
    Par défaut Bien vu l'as !
    @ AndNotOr, bien vu l'ami, ce qui revient au même mais plus simple !

    A noter aussi qu'avec D6, Col et Row sont ACol et Arow :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    procedure TForm1.StringGrid2SelectCell(Sender: TObject; ACol,ARow: Integer; var CanSelect: Boolean);
    var
       R: TRect;
    begin
    .......
    Mon code incrémentait aussi le combobox suivant le nbre de lignes

    @+,

    cincap

Discussions similaires

  1. [JTable] Ajouter un combobox dans une cellule
    Par monpseudonom dans le forum Composants
    Réponses: 1
    Dernier message: 08/04/2008, 00h34
  2. Afficher des Couleurs dans les Cellules automatiquement
    Par dreams11 dans le forum Macros et VBA Excel
    Réponses: 7
    Dernier message: 04/11/2007, 22h17
  3. Réponses: 3
    Dernier message: 04/04/2007, 14h18
  4. ajouter des .jar dans les fichiers de config
    Par C_C dans le forum NetBeans
    Réponses: 5
    Dernier message: 17/11/2006, 15h20
  5. JTable avec des JPanel dans les cellule
    Par pigpen dans le forum Composants
    Réponses: 11
    Dernier message: 13/04/2006, 19h58

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