Autor Beitrag
juergen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 87



BeitragVerfasst: Fr 14.02.03 10:32 
Hallo,

wie kann ich in einem Stringgrid Zellen durch Ziehen mit dem Cursor kopieren wie in EXCEL ?

Bsp.:
Picke auf cells[1,1] wo "test" drinsteht und ziehe dann mit der Maus auf
cells[1,10].
Alle cells der Spalte von [1,1] bis [1,10] sollen nun den Text "test" enthalten.

DANKE

Juergen
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 14.02.03 10:38 
Eine direkte Lösung weiß ichjetzt auch nicht. Aber ansetzen würde ich bei folgender Methode von TStringGrid: MouseToCell. Diese gibt dir die Mouse-Koordinaten der Zelle zurück, die unter der Maus sind.
Bei OnMouseUp kucken welche Zelle es ist und dann auswerten.

Doch noch schnell was gebastelt:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure TForm1.FormCreate(Sender: TObject);
begin
  StringGrid1.Cells[0,0] := 'Test';
end;

procedure TForm1.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  row, column: Integer;
  i,j : Integer;
begin
  StringGrid1.MouseToCell(x,y,row,column);
  for i := 0 to row do
  begin
    for j := 0 to column do
    begin
      StringGrid1.Cells[i,j] := 'Test';
    end;
  end;
end;

Sehr rudimentär. Es wird immer der Text in der Zelle [0,0] in die anderen Zellen geschrieben. Aber es sollte eigentlich reichen, um was daraus zu machen.
juergen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 87



BeitragVerfasst: Fr 14.02.03 11:31 
Danke Luckie,

der Ansatz hat mich zum Ziel begracht !

Falls es jemanden interessiert:

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:
37:
38:
39:
40:
41:
42:
43:
44:
procedure TForm1.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);

var
  row, column, column_start, row_start, i, j : Integer;
begin
  try
  StringGrid1.MouseToCell(x,y,row,column);
  showmessage(inttostr(row)+' '+inttostr(column));
  if (row > 0) and  (column > 0) then
  begin
  if (row_start <= row) and (column_start <= column) then
  for i := row_start to row do
    for j := column_start to column do
      StringGrid1.Cells[i,j] := s
  else
  if (row_start >= row) and (column_start <= column) then
  for i := row_start downto row do
    for j := column_start to column do
      StringGrid1.Cells[i,j] := s
  else
  if (row_start <= row) and (column_start >= column) then
  for i := row_start to row do
    for j := column_start downto column do
      StringGrid1.Cells[i,j] := s
      else
  if (row_start >= row) and (column_start >= column) then
  for i := row_start downto row do
    for j := column_start downto column do
      StringGrid1.Cells[i,j] := s;
  end;
  except
  end;
end;

procedure TForm1.StringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
        StringGrid1.MouseToCell(x,y,row,column);
        row_start:=row;
        column_start:=column;
        s:=stringgrid1.cells[row,column];

end;

juergen