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

C++Builder Discussion :

probleme de Drag and Drop [Non suivi]


Sujet :

C++Builder

Vue hybride

Message pr�c�dent Message pr�c�dent   Message suivant Message suivant
  1. #1
    Membre confirm�
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    107
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 107
    Par d�faut probleme de Drag and Drop
    bonjour
    j'ai une question concernant le Drag and drop , en fait j'ai deux listebox une contient des elements et l'autre pas , ce que je souhaite faire est que l'utilisateur peut remplir la 2eme listbox a partir de la premiere en faisant des drag and drop des element qu'il veut metre .

    j'ai essay� avec le OnDragDrop de Event , mais sans success
    est ce que quelqu'un peut me donner une exemple ou meme une id�e comment on peut faire ca
    merci d'avance

  2. #2
    Membre chevronn� Avatar de BigBenQ
    Inscrit en
    Juillet 2005
    Messages
    363
    D�tails du profil
    Informations forums :
    Inscription : Juillet 2005
    Messages : 363
    Par d�faut
    V'la un p'tit exemple.

    D�sol� il est un peu polu� par des trucs perso

    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
    void __fastcall TClasseurMainForm::ListBoxChapitreDragDrop(TObject *Sender,
          TObject *Source, int X, int Y)
    {
      if (Sender!=Source && Source->ClassNameIs("TListBox"))
      {
        TListBox *DestList = (TListBox *)Sender;
        TPoint* point = new TPoint(X,Y);
     
        DestiListIndex = DestList->ItemAtPos(*point,false);
        DestiListType =((TListBox *)Source)->Items->operator [](((TListBox *)Source)->ItemIndex) ;
        TFParamListe* FParamLst = new TFParamListe(this);
        FParamLst->TypeAjout = "DansListe";
        FParamLst->ShowModal();
        delete point;
        delete FParamLst;
      }
      if (Sender==Source)
      {
        TListBox *DestList = (TListBox *)Sender;
        if (DestList->ItemIndex>=0)
        {
            TPoint* point = new TPoint(X,Y);
            DestList->Items->Insert(DestList->ItemAtPos(*point,false),DestList->Items->operator [](DestList->ItemIndex)) ;
            DestList->Items->Delete(DestList->ItemIndex);
            delete point;
        }
      }
     
     
    }

  3. #3
    Membre confirm�
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    107
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 107
    Par d�faut
    merci beaucoup
    je vais travaill� dessus
    j'ai pas tous compris , mais je te poserrai des question au fur et a mesur
    quand j'avance si tu le permet bien evidement

    merci

  4. #4
    Membre chevronn� Avatar de BigBenQ
    Inscrit en
    Juillet 2005
    Messages
    363
    D�tails du profil
    Informations forums :
    Inscription : Juillet 2005
    Messages : 363
    Par d�faut
    Pas de probl�me, n'h�sites pas

  5. #5
    Membre confirm�
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    107
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 107
    Par d�faut
    bonjour
    j'ai essay� votre code mais je n'ai pas compris cette partis



    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    if (Sender!=Source && Source->ClassNameIs("TListBox")) 
      { 
        TListBox *DestList = (TListBox *)Sender; 
        TPoint* point = new TPoint(X,Y); 
     
        DestiListIndex = DestList->ItemAtPos(*point,false); 
        DestiListType =((TListBox *)Source)->Items->operator [](((TListBox *)Source)->ItemIndex) ; 
        TFParamListe* FParamLst = new TFParamListe(this); 
        FParamLst->TypeAjout = "DansListe"; 
        FParamLst->ShowModal(); 
        delete point; 
        delete FParamLst; 
      }
    en particlulier DestiListIndex , DestiListType et TFParamListe qui ne sont pas d�clarer
    Est ce que la listebox source s'apple ListBoxChapitre
    et la liste destination s'appelle DestiList
    merci d'avance pour ton aide

  6. #6
    Membre chevronn� Avatar de BigBenQ
    Inscrit en
    Juillet 2005
    Messages
    363
    D�tails du profil
    Informations forums :
    Inscription : Juillet 2005
    Messages : 363
    Par d�faut
    Voila une version plus "g�n�rale".
    Mon exemple �t� un peu compliqu�.

    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
    void __fastcall TClasseurMainForm::ListBoxChapitreDragDrop(TObject *Sender,
          TObject *Source, int X, int Y)
    {
      if (Sender!=Source && Source->ClassNameIs("TListBox"))
      {
        TListBox *DestList = (TListBox *)Sender;
        TPoint* point = new TPoint(X,Y);
     
        int DestiListIndex = DestList->ItemAtPos(*point,false);
        AnsiString MaLigne =((TListBox *)Source)->Items->operator [](((TListBox *)Source)->ItemIndex) ;
        ListBoxChapitre->Items->Insert(DestiListIndex,MaLigne);
        delete point;
      }
    }
     
    En espérant t'avoir aidé  :)

  7. #7
    Membre exp�riment� Avatar de Bily.sdi
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    208
    D�tails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 208
    Par d�faut voila un exmple complet
    sorry mais je suis nouveau ici et j'ai pas trouv� ou je peux mettre mes programmes pour qu'ils soient telechargeables !!
    ------------------------------------------------------------------------------------
    pour creer le projet , ouvrez une form , " c++builder5 et sup "
    plcez un TBouton Button1 et une TImageList appel� ImageList1
    dans la TImageList mettez y 5 images
    ----------------------------------------------------------------------------------
    voici le 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
    //---------------------------------------------------------------------------
     
    #include <vcl.h>
    #pragma hdrstop
     
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
        p1 = new TPiece(this,ImageList1,0,0,0,"VEGETA");
        p2 = new TPiece(this,ImageList1,1,150,0,"BULMA");
        p3 = new TPiece(this,ImageList1,2,300,0,"SANGOKU");
        p4 = new TPiece(this,ImageList1,3,450,0,"TENSHINAN");
        p5 = new TPiece(this,ImageList1,4,600,0,"BOUBOU");
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
        p1->Positionner(0,0);
        p2->Positionner(150,0);
        p3->Positionner(300,0);
        p4->Positionner(450,0);
        p5->Positionner(600,0);
    }
    //---------------------------------------------------------------------------
     __fastcall TPiece::TPiece(TForm *AOwner, TImageList *liste, int index,
        int posX, int posY,AnsiString n) :
            TImage(AOwner)
    {
        listeImg = liste;
        this->numero = index;
        listeImg->GetBitmap(numero,Picture->Bitmap);
        this->nom    = n;
        this->Width  = Picture->Width;
        this->Height = Picture->Height;
        this->Parent = AOwner;
        this->Top    = posY;
        this->Left   = posX;
        this->Hint   = nom;
        this->ShowHint = true;
        this->Transparent = false;
    }
    //------------------------------------------------------------------------
    void __fastcall TPiece::Positionner(int X, int Y)
    {
         this->Top = Y;
     
         this->Left = X;
    }
    //------------------------------------------------------------------------
    void __fastcall TPiece::MouseDown(TMouseButton button, TShiftState shift,
                 int X, int Y)
    {
        listeImg->DragCursor = crHandPoint;
     
        listeImg->Tag=this->numero;
     
        listeImg->SetDragImage(this->numero,X,Y);
     
        this->deltaX = X-this->Left;
     
        this->deltaY = Y-this->Top;
     
        listeImg->BeginDrag(this->Parent->Handle,this->Left+X,this->Top+Y);
    }
    //------------------------------------------------------------------------
    void __fastcall TPiece::MouseMove( TShiftState shift,
                 int X, int Y)
    {
        if(listeImg->Dragging)
            listeImg->DragMove(this->Left+X,this->Top+Y);
        else
            this->Parent->Cursor = crHandPoint;
    }
    //------------------------------------------------------------------------
    void __fastcall TPiece::MouseUp(TMouseButton button, TShiftState shift,
             int X, int Y)
    {
        if(listeImg->Dragging)
        {
            this->Top  = Y - this->deltaY;
     
            this->Left = X - this->deltaX;
     
            listeImg->EndDrag();
        }
    }
    //---------------------------------------------------------------------------
    le code unit1.h
    //---------------------------------------------------------------------------
    //---------------------------------------------------------------------------
     
    #ifndef Unit1H
    #define Unit1H
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    #include <ImgList.hpp>
    #include <Buttons.hpp>
    #include <ExtCtrls.hpp>
    #include <jpeg.hpp>
    //---------------------------------------------------------------------------
    class TPiece;
     
    class TForm1 : public TForm
    {
    __published:	// Composants gérés par l'EDI
        TImageList *ImageList1;
        TButton *Button1;
        void __fastcall Button1Click(TObject *Sender);
        void __fastcall FormCreate(TObject *Sender);
    private:	// Déclarations utilisateur
    public:		// Déclarations utilisateur
        __fastcall TForm1(TComponent* Owner);
     
        TPiece *p1, *p2, *p3 , *p4 , *p5;
     
         int XX,YY;
    };
     
     
    class TPiece : public TImage
    {
        TImageList *listeImg;
        int numero;
        AnsiString nom;
     
        int deltaX, deltaY;
        DYNAMIC void __fastcall MouseDown(TMouseButton, TShiftState, int, int);
        DYNAMIC void __fastcall MouseMove( TShiftState, int, int);
        DYNAMIC void __fastcall MouseUp(TMouseButton, TShiftState, int, int);
      public:
        __fastcall TPiece(TForm * ,TImageList *,int, int, int, AnsiString);
        void __fastcall Positionner(int , int);
     
     
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm1 *Form1;
    //---------------------------------------------------------------------------
    #endif
    @++

  8. #8
    Membre exp�riment� Avatar de Bily.sdi
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    208
    D�tails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 208
    Par d�faut suite
    si tu veux passez un texte d'une liste a l'autre

    travaille avec List->ItemIndex
    tu le supprime de la liste A mais avant tu l'ajoute dans la liste B

    @++

  9. #9
    Membre �clair�
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    71
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 71
    Par d�faut
    Bonjour

    Compl�ment au code de BigBenQ : il faut mettre la propri�t� DragMode des ListBox � dmAutomatic et fournir un gestionnaire d'�v�nement pour la m�thode OnDragOver qui mette Accept � true.

    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    void __fastcall TForm1::ListBoxChapitreDragOver(TObject *Sender, TObject *Source,
    	  int X, int Y, TDragState State, bool &Accept)
    {
      Accept = Source->ClassNameIs("TListBox");
    // ou simplement Accept = true;
    }

Discussions similaires

  1. Drag and drop "de l'ext�rieur"
    Par Invit� dans le forum C++Builder
    R�ponses: 12
    Dernier message: 31/03/2020, 10h10
  2. [SP-2010] Probleme Drag and Drop?
    Par john85 dans le forum SharePoint
    R�ponses: 0
    Dernier message: 16/05/2012, 09h28
  3. probleme de Drag and drop dans une DataRepeater
    Par LibidoPostToxico dans le forum VB.NET
    R�ponses: 0
    Dernier message: 24/06/2010, 17h32
  4. Drag and Drop Probleme DLL
    Par borislotte dans le forum VBA Access
    R�ponses: 5
    Dernier message: 21/03/2007, 18h56
  5. Drag and drop problemes
    Par jean dans le forum GTK+ avec C & C++
    R�ponses: 3
    Dernier message: 09/11/2006, 16h26

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