Autor Beitrag
bayou
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 88


D6 PE
BeitragVerfasst: Mi 12.09.07 10:04 
Hi Leute,

ich habe längere Zeit gesucht aber leider nichts richtiges gefunden.
Ich möchte aus einem StringGrid markierte Zeilen via Drag & Drop in eine 2. StringGrid kopieren.
Kann mir jemand dabei helfen?

Mit einem Button sieht es folgendermaßen aus.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TFormMain.SpeedButtonAddToPlaylistClick(Sender: TObject);
var
  i : integer;
  mdata : TMusicData;
  mr : TModalResult;
begin
  if (musiclist.getItemCount > 0) then
  begin
    mr := mrCancel;
    for i := StringGridInventory.Selection.Top to StringGridInventory.Selection.Bottom do
    begin
      mdata := musiclist.getMusicDataPK(StrToInt(StringGridInventory.Cells[ML_COL_PRIMARY, i]));
      playlist.addMusicData(mdata, mr);
    end;
    refreshStringGridPlayList();
  end;
end;


Vielen Dank für eure Hilfe

Moderiert von user profile iconjasocul: Delphi-Tags eingefügt


Zuletzt bearbeitet von bayou am Fr 14.09.07 11:09, insgesamt 1-mal bearbeitet
bayou Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 88


D6 PE
BeitragVerfasst: Do 13.09.07 13:34 
also ich bin im Moment so weit.

StringGridInventory (also StringGrid1) auf DragMod = dmAutomatic

in StringGridPlayList (also StringGrid2) folgendes:

ausblenden Delphi-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:
procedure TFormMain.StringGridPlayListDragOver(Sender, Source: TObject; X,
  Y: Integer; State: TDragState; var Accept: Boolean);
begin
  Accept := Source = StringGridInventory;
end;

procedure TFormMain.StringGridPlayListDragDrop(Sender, Source: TObject; X,
  Y: Integer);
var
  i : integer;
  mdata : TMusicData;
  mr : TModalResult;
begin
//  if (Sender = StringGridPlayList) and (Source = StringGridInventory) then
//  begin
    with StringGridPlayList do
    begin
  if (musiclist.getItemCount > 0) then
  begin
    mr := mrCancel;
    for i := StringGridInventory.Selection.Top to StringGridInventory.Selection.Bottom do
    begin
      mdata := musiclist.getMusicDataPK(StrToInt(StringGridInventory.Cells[ML_COL_PRIMARY, i]));
      playlist.addMusicData(mdata, mr);
    end;
    refreshStringGridPlayList();
  end;
//    end;
  end;
end;


Leider funktioniert dann aber in StringGridInventory die OnClick und andere Funktionen nicht mehr.

Kann mir evt. jemand sagen was ich falsch mache?
Vielen Dank
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 13.09.07 21:43 
Moin!

user profile iconbayou hat folgendes geschrieben:
also ich bin im Moment so weit.

StringGridInventory (also StringGrid1) auf DragMod = dmAutomatic
[...]
Leider funktioniert dann aber in StringGridInventory die OnClick und andere Funktionen nicht mehr.

Interpretiere ich das richtig: der Code läuft so wie gezeigt für das d&d, ja?

user profile iconbayou hat folgendes geschrieben:
Kann mir evt. jemand sagen was ich falsch mache?

Wenn es (nur) darum geht, dass OnClick dann im Stringgrid nicht mehr funktioniert - gar nichts. ;) Das ist "normal", wenn man dmAutomatic verwendet. :nixweiss:

Jetzt klären wir erstmal, ob das d&d bzw. Kopieren funktioniert. :idea:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
bayou Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 88


D6 PE
BeitragVerfasst: Do 13.09.07 21:46 
Hi und danke für deine Antwort.

Wenn ich dmAutomatic eingestellt habe wird in der StringGrid1 die erste Zeile markiert.
Es ist möglich die erste Zeile in die andere StringGrid zu schieben, ich kann aber keine ander Zeile markieren da das OnClick nicht funktioniert.

Ist es möglich d&d ohne dmAutomatic zu verwenden?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 13.09.07 22:17 
Moin!

Hier das Konzept, um d&d manuell einzuleiten :arrow: die d&d-Quell-Kompo wieder auf dmManual zurückstellen!
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
// d&d annehmen
procedure TForm1.StringGrid2DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  Accept := (Source = StringGrid1);
end;

// d&d ausführen
procedure TForm1.StringGrid2DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
  if (Source = StringGrid1) then begin
    // Dinge tun, d&d verarbeiten
  end;
end;

// d&d einleiten, ohne OnClick zu blockieren
procedure TForm1.StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  (Sender as TStringGrid).BeginDrag(FALSE);
end;

Schau mal, ob du damit weiter kommst. :idea: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
bayou Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 88


D6 PE
BeitragVerfasst: Do 13.09.07 22:45 
funktioniert klasse, dafür schon mal danke.

Leider kann ich jetzt immer nur eine Zeile markieren.
Ich denke aber, dafür eine Lösung zu finden wird ein größerer Aufwand als ich zur Zeit investieren möchte.

nochmals Danke