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

Langage Delphi Discussion :

Bouton supprimer dans un DBAdvGrid


Sujet :

Langage Delphi

  1. #1
    Membre habitué

    Homme Profil pro
    Développeur multimédia
    Inscrit en
    Février 2013
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Landes (Aquitaine)

    Informations professionnelles :
    Activité : Développeur multimédia
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2013
    Messages : 148
    Points : 199
    Points
    199
    Par défaut Bouton supprimer dans un DBAdvGrid
    Bonjour,

    J'ai encore un petite question
    J'ai un DBAdvGrid dans lequel je veux afficher un bouton pour supprimer une ligne d'enregistrement.
    Directement dans le DBAdvGrid c'est rapé.
    Du coup, je pense rajouter un champs dans le clientdataset, et lui assigner une image comme valeur.

    J'arrive quand même à récupérer le clic sur l'image que je n'arrive pas à afficher, cela dans le form
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    procedure TAirClientForm.DBAdvGrid1ClickCell(Sender: TObject; ARow,
      ACol: Integer);
    begin
    if(ACol= 3)then ShowMessage('clic sur l''image');
    end;
    Mais je coince sur le clientdataset, voici mon code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    procedure TClientModule.afterApplyUpdateAddDelPicture(Sender: TObject;
      var OwnerData: OleVariant);
    begin
        cds_clients.FieldByName('DEL').Value := DmImages.delBtnImage; ??? erreur ici
        cds_clients.Post;
        cds_clients.applyupdates(0);
    end;
    DmImages.delBtnImageest un TImageList

  2. #2
    Membre habitué

    Homme Profil pro
    Développeur multimédia
    Inscrit en
    Février 2013
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Landes (Aquitaine)

    Informations professionnelles :
    Activité : Développeur multimédia
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2013
    Messages : 148
    Points : 199
    Points
    199
    Par défaut
    Bonjour !

    Bon toujours coinçé sur l'ajout d'une image dans mon clientdataset.
    J'ai crée un champs sur mon clientdataset.
    J'ai hésité entre le type blob et graphic...?
    Ensuite, j'ai appellé la méthode suivante sur l'evenement AfterOpen de mon clientdataset

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    procedure TClientModule.assignImageToDataSetField(dataset : TClientDataSet; fieldName, image : string);
    begin
        with dataset do begin;
             Open;
             Edit;
             TBlobField(FieldByName(fieldName)).LoadFromFile(image);
             Post;
        end;
    end;
    SI de plus je pouvais me passer du LoadFromFile() et utiliser une TImage de mon TImageList j'en serais plus heureux...Mais je coince sur tout ça

  3. #3
    Membre habitué

    Homme Profil pro
    Développeur multimédia
    Inscrit en
    Février 2013
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Landes (Aquitaine)

    Informations professionnelles :
    Activité : Développeur multimédia
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2013
    Messages : 148
    Points : 199
    Points
    199
    Par défaut
    J'ai crée un champs auquel j'ai codé à au getText() :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    procedure TClientModule.cds_clientsDELGetText(Sender: TField; var Text: string;
      DisplayText: Boolean);
     begin
          with Sender.DataSet do begin;
          Edit;
          FieldByName('DEL').Assign(DmImages.delBtnImage);
          Post;
     end;
    end;
    mais ca ne marche toujours pas, ni avec du blob ou graphic comme type de champs...

  4. #4
    Membre habitué

    Homme Profil pro
    Développeur multimédia
    Inscrit en
    Février 2013
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Landes (Aquitaine)

    Informations professionnelles :
    Activité : Développeur multimédia
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2013
    Messages : 148
    Points : 199
    Points
    199
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    procedure TClientModule.cds_clientsDELGetText(Sender: TField; var Text: string;DisplayText: Boolean);
    var
       imageField: TGraphicField;
    begin
         imageField := Sender.DataSet.FieldByName('DEL') as TGraphicField;
           with Sender.DataSet do begin;
              Edit;
              imageField.Assign(DmImages.delBtnImage);
              Post;
          end;
    end;
    Idem...

  5. #5
    Membre habitué

    Homme Profil pro
    Développeur multimédia
    Inscrit en
    Février 2013
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Landes (Aquitaine)

    Informations professionnelles :
    Activité : Développeur multimédia
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2013
    Messages : 148
    Points : 199
    Points
    199
    Par défaut
    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
     
    procedure TAirClientForm.ClientsGridPainted(Sender: TObject);
    var
       imageField: TGraphicField;
       deleteImage: TImage;
    begin
         with ClientModule.cds_clients do begin;
            imageField := FieldByName('DEL') as TGraphicField;
            deleteImage.Picture.Bitmap.TransparentMode := tmFixed;
            deleteImage.Picture.Bitmap.TransparentColor := clWhite;
            deleteImage.Picture.Bitmap := nil;
            DmImages.delBtnImage.GetBitmap(0, deleteImage.Picture.Bitmap);
            Edit;
            imageField.Assign(deleteImage.Picture.Bitmap);
            Post;
         end;
    end;
    Pareil...grrrrr

  6. #6
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 105
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 68
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 105
    Points : 41 195
    Points
    41 195
    Billets dans le blog
    63
    Par défaut
    Citation Envoyé par LaurentC33 Voir le message
    J'ai un DBAdvGrid dans lequel je veux afficher un bouton pour supprimer une ligne d'enregistrement.
    Directement dans le DBAdvGrid c'est rapé.
    pourquoi ? je ne connais pas (ou plutôt je n'ai jamais utilisé) DBAdvGrid mais cela doit être un descendant d'un DBGrid ou d'un CustomDBGrid , il doit bien y avoir un event onDrawColumnCell ?
    [Edit] après vérification il y a au moins un ondrawcell
    Du coup, je pense rajouter un champs dans le clientdataset, et lui assigner une image comme valeur.
    mauvaise pioche à mon avis , il vaudrait mieux s'inspirer de la FAQ http://delphi.developpez.com/faq/?pa...eacocherdbgrid
    ou aller voir du coté d'un DrawFrameControl
    Code Bouton en colonne 3 : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    procedure TForm1.DBAdvGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    var r : TRect;
    begin
    if acol=3 and Arow>0 then
     begin
        r.Top:=Rect.Top+1;
      r.Bottom:=Rect.Bottom-1;
      r.Left:=Rect.Left+1;
      r.Right:=Rect.Right-1;
      DrawFrameControl((Sender as TDBAdvGrid).Canvas.Handle,r,DFC_BUTTON, dfcs_buttonpush);
     end;
    end;
    ce code rapide affiche un bouton sans texte

  7. #7
    Membre habitué

    Homme Profil pro
    Développeur multimédia
    Inscrit en
    Février 2013
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Landes (Aquitaine)

    Informations professionnelles :
    Activité : Développeur multimédia
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2013
    Messages : 148
    Points : 199
    Points
    199
    Par défaut
    Merci mille fois

    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
     
    procedure TAirClientForm.drawDelButton(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
    var canvas : TCanvas;
    begin;
          // On affiche l'image toujours sur la dernière colonne
          if (acol = (Sender as TDBAdvGrid).Columns.Count - 1) and (Arow > 0) then begin
           canvas := (Sender as TDBAdvGrid).Canvas;
           canvas.FillRect(Rect);
           DmImages.delBtnImage.draw(
              // Surface de dessin sur laquelle l'image doit être restituée
              canvas,
              // Emplacement du coin supérieur gauche dans le canevas
              Rect.Left + ((Rect.Right - Rect.Left - DmImages.delBtnImage.Width) div 2),
              Rect.Top,
              // Index de l'image à dessiner
              0
          );
          end;
    end;

Discussions similaires

  1. Réglage interface pour bouton supprimer dans un tableau
    Par Popa_Cubede dans le forum Mise en page CSS
    Réponses: 3
    Dernier message: 15/07/2014, 09h18
  2. Problème dans le bouton Supprimer
    Par Lavinyo dans le forum Débuter avec Java
    Réponses: 4
    Dernier message: 11/06/2014, 09h11
  3. Supprimer bouton 'Nouveau' dans une liste
    Par neo.96 dans le forum SharePoint
    Réponses: 6
    Dernier message: 15/07/2009, 13h40
  4. Evenement pour caractere ajouté ou supprimé dans un input ?
    Par Jerem' dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 18/02/2005, 14h11
  5. [VB6] Api pour supprimer dans un fichier INI
    Par Argonz dans le forum VB 6 et antérieur
    Réponses: 7
    Dernier message: 20/02/2003, 08h16

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