| 12
 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
 
 | void __fastcall TForm1::ListBox1DragOver(TObject *Sender, TObject *Source,
      int X, int Y, TDragState State, bool &Accept)
{
        Accept=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox2DragOver(TObject *Sender, TObject *Source,
      int X, int Y, TDragState State, bool &Accept)
{
        //gestion multiselect : au moins 1 doit etre selectionné
        Accept=false;
        for (int i=0;i<ListBox1->Items->Count && !Accept;i++){
           if(ListBox1->Selected[i]) Accept=true;
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox2DragDrop(TObject *Sender, TObject *Source,
      int X, int Y)
{
        for (int i=0;i<ListBox1->Items->Count;i++)
        {
           if(ListBox1->Selected[i]){
                String ItemTexte = ListBox1->Items->Strings[i];
 
                //choisir ça si la place d'arrivée ne compte pas..
                //ListBox2->Items->Add(ItemTexte);
 
                //sinon si la place d'arrivée compte
                TPoint pt;
                pt.x=X;
                pt.y=Y;
                int item_pos = ListBox2->ItemAtPos(pt,true);
                if(item_pos==-1){
                  ListBox2->Items->Add(ItemTexte);
                }else{
                    ListBox2->Items->Insert(item_pos,ItemTexte);
                }
 
           }
 
        }
        //optionnel : pour effacer de la source
        ListBox1->DeleteSelected();
 
        ListBox2->SetFocus();
} | 
Partager