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

Bases de données Delphi Discussion :

besoin d'aide pour le composant DBComboBox


Sujet :

Bases de données Delphi

  1. #1
    Nouveau membre du Club

    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 7
    Points : 25
    Points
    25
    Par défaut besoin d'aide pour le composant DBComboBox
    Bonjour,

    voila j'ai creer une fiche, et je voudrais utiliser le composant DBComboBox pour afficher, par exemple le "nom client" a l'interieur du DBCombBox.
    J'ai placé sur ma fiche un composant DataSource et un DBComboBox
    donc pour le DBComboBox j'ai rempli les proprietes DataSource et DataFields et pour mon composant DataSource j'ai rempli la propriete DataSet
    Le probleme etant que je n'arrive pas a afficher le nom de mes clients dans le DBComboBox.

    Je remercie d'avance a qui veut bien m'aider

  2. #2
    Expert éminent
    Avatar de Lung
    Profil pro
    Analyste-programmeur
    Inscrit en
    Mai 2002
    Messages
    2 664
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Analyste-programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2002
    Messages : 2 664
    Points : 6 967
    Points
    6 967
    Par défaut
    Il faut remplir le ComboBox toi-même, avec une boucle.

    L'urgent est fait, l'impossible est en cours, pour les miracles prévoir un délai. ___ Écrivez dans un français correct !!

    C++Builder 5 - Delphi 6#2 Entreprise - Delphi 2007 Entreprise - Delphi 2010 Architecte - Delphi XE Entreprise - Delphi XE7 Entreprise - Delphi 10 Entreprise - Delphi 10.3.2 Entreprise - Delphi 10.4.2 Entreprise - Delphi 11.1 Entreprise
    OpenGL 2.1 - Oracle 10g - Paradox - Interbase (XE) - PostgreSQL (15.4)

  3. #3
    Nouveau membre du Club

    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 7
    Points : 25
    Points
    25
    Par défaut
    oui j'ai essayer avec une boucle tant que mais il ne lis pas les infos de ma table, la synthaxe pour lire les donnees d'une table c'est bien
    DataSource.TTable.FieldByName('NomTable').asstring
    par contre cela ce declenche sur l'evenement OnEnter alors je sais si c vraiment bon

  4. #4
    Inactif  

    Inscrit en
    Mars 2002
    Messages
    18
    Détails du profil
    Informations forums :
    Inscription : Mars 2002
    Messages : 18
    Points : 111
    Points
    111
    Par défaut
    Recherche sur Eof
    http://www.egri.co.uk/smileys/walk.gif http://www.developpez.com/delphi/delphihlp.htm
    - Delphi Studio 7 Architecte.
    - Interbase / SQL Server 2000 / Oracle 9i
    - Windows (2000 Famille Server, 98, Me, XP Professionnel).

  5. #5
    Nouveau membre du Club
    Inscrit en
    Août 2002
    Messages
    36
    Détails du profil
    Informations forums :
    Inscription : Août 2002
    Messages : 36
    Points : 37
    Points
    37
    Par défaut
    Composant

    Par : Veeranna Ronad

    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
    unit DBCustCB; 
     
    interface 
     
    uses 
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,   DBCtrls, Db, DBTables, StdCtrls, DBGrids; 
     
    type 
      TMSDBComboBox = class(TComboBox) 
      private 
        { Private declarations } 
        FDataSource  : TDataSource; 
        FDataField   : TField; 
        FFieldName   : String; 
        FDBGrid      : TDBGrid; 
        FCellClicked : Boolean; 
        FBookmark    : TBookmark; 
        FDBComboBoxOnEnter  : Boolean; 
        procedure CreateGridNColumn; 
        procedure Click(var message: TWMLButtonDown); message WM_LBUTTONDOWN; 
        procedure DBGridEnter(Sender : TObject); 
        procedure DBGridExit(Sender : TObject); 
        procedure CellClick(Column : TColumn); 
        procedure AssignText; 
        procedure WMPaste(var Message : TMessage);message WM_Paste; 
        procedure WMCut(var Message: TMessage); message WM_CUT; 
        procedure WMKeyDown(var Message: TWMKeyDown); message WM_KEYDOWN; 
      protected 
        { Protected declarations } 
        procedure Loaded; override; 
        procedure DoEnter; override; 
        procedure DoExit; override; 
      public 
        { Public declarations } 
        constructor Create(AOwner: TComponent); override; 
        destructor Destroy; override; 
      published 
        { Published declarations } 
        property DataField : String read FFieldName write FFieldName; 
        property DataSource : TDataSource read FDataSource write FDataSource; 
      end; 
     
    procedure Register; 
     
    implementation 
     
    constructor TMSDBComboBox.Create(AOwner: TComponent); 
    begin 
      inherited Create(AOwner); 
      ControlStyle := ControlStyle + [csReplicatable]; 
      CreateGridNColumn; 
    end; 
     
    procedure TMSDBComboBox.DoEnter; 
    begin 
      if not FDBComboBoxOnEnter then begin 
        inherited; 
        FDBComboBoxOnEnter := True; 
      end; 
    end; 
     
    procedure TMSDBComboBox.DoExit; 
    begin 
      inherited; 
      if not (Screen.ActiveControl = FDBGrid) then 
        FDBComboBoxOnEnter := False; 
    end; 
     
    procedure TMSDBComboBox.Click(var message: TWMLButtonDown); 
    var 
      SelfPoint : TPoint; 
      SelfExit : TNotifyEvent; 
    begin 
      try 
        SelfExit := Self.OnExit; 
        Self.OnExit := nil; 
        FCellClicked := False; 
        FBookmark := DataSource.DataSet.GetBookmark; 
        if not FDBComboBoxOnEnter then 
          Self.DoEnter; 
        FDataField := DataSource.DataSet.FieldByName(FFieldName); 
        FDBGrid.Parent := Screen.ActiveForm; 
        FDBGrid.Width := Self.Width; 
        FDBGrid.DataSource := DataSource; 
        FDBGrid.Columns.Items[0].Field := FDataField; 
        FDBGrid.Columns.Items[0].Width := Self.Width - 22; 
        FDBGrid.Enabled := True; 
        SelfPoint := Screen.ActiveForm.ScreenToClient(Self.Parent.ClientToScreen(Point(Self.Left,Self.Top))); 
        FDBGrid.Left := SelfPoint.X; 
        if ((Screen.ActiveForm.Height - SelfPoint.Y) >= FDBGrid.Height) then begin 
            FDBGrid.Top := SelfPoint.Y + Self.Height 
          end 
        else 
          begin 
            FDBGrid.Top := SelfPoint.Y - FDBGrid.Height; 
          end; 
        FDBGrid.DataSource := Self.DataSource; 
        FDBGrid.BringToFront; 
        FDBGrid.Visible := True; 
        FDBGrid.SetFocus; 
      finally 
        Self.OnExit := SelfExit; 
      end; 
    end; 
     
    procedure TMSDBComboBox.DBGridExit(Sender : TObject); 
    begin 
      inherited; 
      FDBGrid.Parent := Self; 
      FDBGrid.Visible := False; 
      if not FCellClicked then begin 
        try 
          DataSource.DataSet.GotoBookmark(FBookmark); 
        finally 
          DataSource.DataSet.FreeBookmark(FBookmark); 
        end; 
      end; 
      Self.SetFocus; 
    end; 
     
    procedure TMSDBComboBox.DBGridEnter(Sender : TObject); 
    begin 
    {  FCellClicked := False; 
      FBookmark := DataSource.DataSet.GetBookmark; 
      Self.OnEnter(Self);} 
    end; 
     
    procedure TMSDBComboBox.CellClick(Column : TColumn); 
    begin 
      FCellClicked := True; 
      AssignText; 
      FDBGrid.Visible := False; 
      Self.SetFocus; 
      if Assigned(Self.OnClick) then 
        Self.OnClick(Self); 
    end; 
     
    procedure TMSDBComboBox.AssignText; 
    begin 
      if (DataSource.DataSet.FindField(FFieldName) <> nil) then 
        Self.Text := DataSource.DataSet.FindField(FFieldName).AsString; 
    end; 
     
    procedure TMSDBComboBox.Loaded; 
    begin 
      inherited; 
      Self.ItemHeight := 0; 
      Self.Text := ''; 
    end; 
     
    procedure TMSDBComboBox.CreateGridNColumn; 
    begin 
      FDBGrid := TDBGrid.Create(Self); 
      FDBGrid.Left := 1000; 
      FDBGrid.Top := 1000; 
      FDBGrid.Parent := Self; 
      FDBGrid.Options := FDBGrid.Options - [dgTitles,dgIndicator]; 
      FDBGrid.Options := FDBGrid.Options + [dgRowSelect,dgTabs]; 
      FDBGrid.Columns.Add; 
      FDBGrid.Visible := False; 
      FDBGrid.OnEnter := DBGridEnter; 
      FDBGrid.OnExit := DBGridExit; 
      FDBGrid.OnCellClick := CellClick; 
      FDBGrid.ReadOnly := True; 
      FDBGrid.TabStop := False; 
    end; 
     
    procedure TMSDBComboBox.WMPaste(var Message : TMessage); 
    begin 
      inherited; 
    end; 
     
    procedure TMSDBComboBox.WMCut(var Message: TMessage); 
    begin 
      inherited; 
    end; 
     
    procedure TMSDBComboBox.WMKeyDown(var Message: TWMKeyDown); 
    begin 
      inherited; 
    end; 
     
    destructor TMSDBComboBox.Destroy; 
    begin 
      if (FDBGrid.Parent <> nil) then begin 
        FDBGrid.Free; 
        FDBGrid := nil; 
      end; 
      inherited; 
    end; 
     
    procedure Register; 
    begin 
      RegisterComponents('Delphi 3.0 Components', [TMSDBComboBox]); 
    end; 
     
    end.
    a+
    1 = 3 ?

  6. #6
    Inactif  

    Inscrit en
    Mars 2002
    Messages
    18
    Détails du profil
    Informations forums :
    Inscription : Mars 2002
    Messages : 18
    Points : 111
    Points
    111
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Query.Open 
    while Not Query.Eof do 
    begin 
    ListBox.Iems.Add(Query.FieldbyName('Ville).Asstring); 
    Query.Next; 
    end; 
    Query.Close
    http://www.egri.co.uk/smileys/walk.gif http://www.developpez.com/delphi/delphihlp.htm
    - Delphi Studio 7 Architecte.
    - Interbase / SQL Server 2000 / Oracle 9i
    - Windows (2000 Famille Server, 98, Me, XP Professionnel).

  7. #7
    Nouveau membre du Club

    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 7
    Points : 25
    Points
    25
    Par défaut
    merci pour toutes ces reponses d'ailleurs j'ai reussi a trouver mon bonheur dans tout ca.(un merci en particulier a FW-S, qui m'a donne la solution)
    autre petite question maintenant je vois les champs de ma table dans le DBComboBox mais je n'arrive pas a selectionne les champs (cad que je vois seulement les champs)

  8. #8
    Inactif  

    Inscrit en
    Mars 2002
    Messages
    18
    Détails du profil
    Informations forums :
    Inscription : Mars 2002
    Messages : 18
    Points : 111
    Points
    111
    Par défaut
    marque RESOLU dans ce poste et repose une nouvelle question, plus pratique pour les recherches ultèrieurs des autre participants
    http://www.egri.co.uk/smileys/walk.gif http://www.developpez.com/delphi/delphihlp.htm
    - Delphi Studio 7 Architecte.
    - Interbase / SQL Server 2000 / Oracle 9i
    - Windows (2000 Famille Server, 98, Me, XP Professionnel).

  9. #9
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2002
    Messages
    9
    Détails du profil
    Informations personnelles :
    Âge : 54
    Localisation : Belgique

    Informations forums :
    Inscription : Avril 2002
    Messages : 9
    Points : 10
    Points
    10
    Par défaut
    Tu dois mettre la propriété STYLE à csDropDownList
    Windows 2000
    Delphi 5 Enterprise + composants RXLib
    SQL serveur 2000

Discussions similaires

  1. Besoin d'aide pour une Requête SQL ...
    Par Kokito dans le forum Requêtes
    Réponses: 2
    Dernier message: 07/07/2004, 11h56
  2. besoin d'aide pour une requête
    Par Damien69 dans le forum Langage SQL
    Réponses: 11
    Dernier message: 31/03/2004, 15h38
  3. [Kylix] besoin d'aide pour installer kylix3
    Par Sph@x dans le forum EDI
    Réponses: 3
    Dernier message: 11/02/2004, 13h53
  4. [TP]besoin d'aide pour commandes inconnues
    Par Upal dans le forum Turbo Pascal
    Réponses: 15
    Dernier message: 03/10/2002, 10h48
  5. Besoin d'aide pour l'I.A. d'un puissance 4
    Par Anonymous dans le forum C
    Réponses: 2
    Dernier message: 25/04/2002, 17h05

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