Autor Beitrag
Arakis
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 344



BeitragVerfasst: Fr 31.01.03 10:54 
Kann mir jemand sagen, wie man Drag und Drop mit ListBox-Items machan kann? So wie bei Tabulatorreihenfolge bei der Delphi-IDE.

Bis dann
user defined image

_________________
Mit dem Computer löst man Probleme, die man ohne ihn nicht hätte.
Entwickler von SpaceTrek: The New Empire - Siehe Hompage!
patrick dee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 311

Win 98SE, WinXP
D3,D6
BeitragVerfasst: Fr 31.01.03 11:44 
hi

ich glaube so ungetestet :

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
Accept := Sender is TListBox;

end;
{ DragDrop innerhalb der ListBox }
ausblenden volle Höhe Quelltext
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:
procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
var 
  iTemp : integer; 
  ptTemp : TPoint; 
  szTemp : String; 
begin 
  { change the x,y coordinates into a TPoint record } 
  ptTemp.x:=x; 
  ptTemp.y:=y; 

  { Use a while loop instead of a for loop due to items possible being removed 
   from listboxes this prevents an out of bounds exception } 
  iTemp := 0; 
  While iTemp <= TListBox(Source).Items.Count-1 do 
  begin 
    { look for the selected items as these are the ones we wish to move } 
    if TListBox(Source).selected[iTemp] then 
    begin 
       { use a with as to make code easier to read } 
      With Sender as TListBox do 
      begin 
      { need to use a temporary variable as when the item is deleted the 
        indexing will change } 
        szTemp := TListBox(Source).items[iTemp]; 

      { delete the item that is being dragged  } 
        TListBox(Source).items.Delete(iTemp); 

      { insert the item into the correct position in the listbox that it 
       was dropped on } 
        items.Insert(itemAtPos(ptTemp,true),szTemp); 
      end; 
    end; 
    inc(iTemp); 
  end; 
end;


ciao

_________________
Glauben heißt nichts wissen ...
Arakis Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 344



BeitragVerfasst: Fr 31.01.03 11:56 
Jo, dank dir patrick dee.

Schön wäre es natürlich noch, wenn man mehrere auf einmal verschieben könnte und das das Item unter dem Cursor eine gestrichelte Selektierung hat, aber dass muss nicht zwangläufig sein :wink:

Nochmals danke.

Bis dann
user defined image

_________________
Mit dem Computer löst man Probleme, die man ohne ihn nicht hätte.
Entwickler von SpaceTrek: The New Empire - Siehe Hompage!