Link to home
Start Free TrialLog in
Avatar of koger
koger

asked on

Use TCustomGrid with TStringGrid?

How to use ex. MoveRow from TCustomGrid in a TStringGrid?
Avatar of mirek071497
mirek071497

Normally you can't because you must made some changes in the VCL Source for this. However this code doing that job very fine.

I was create simple form and put on this the string grid and button. after this I was write code to the OnCreate event to fill the StringGrid1 and code to OnClick event for the button. The OnClick exchanging col1 and col2

procedure TForm1.FormCreate(Sender: TObject);
var i,j : integer;
begin
  for j:=0 to StringGrid1.RowCount-1 do
  for i:=0 to StringGrid1.ColCount-1 do
    StringGrid1.Cells[i,j]:=inttostr(j)+';'+inttostr(i);
end;

procedure TForm1.Button1Click(Sender: TObject);
var TmpStringGrid : TStringGrid;
begin
  TmpStringGrid := TStringGrid.Create(self);
  TmpStringGrid.Cols[0] := StringGrid1.Cols[1];
  StringGrid1.Cols[1] := STringGrid1.Cols[2];
  StringGrid1.Cols[2] := TmpStringGrid.Cols[0];
  TmpStringGrid.Free;
end;

****************

Ok You need move Row ? this is the same You must change only the OnClick.

procedure TForm1.Button1Click(Sender: TObject);
var TmpStringGrid : TStringGrid;
begin
  TmpStringGrid := TStringGrid.Create(self);
  TmpStringGrid.Rows[0] := StringGrid1.Rows[1];
  StringGrid1.Rows[1] := STringGrid1.Rows[2];
  StringGrid1.Rows[2] := TmpStringGrid.Rows[0];
  TmpStringGrid.Free;
end;

*******

however This proc creating the MoveRow for all your projects ;)

procedure ExchangeRows( var Grid : TStringGrid; r1,r2 : integer );
var TmpStringGrid : TStringGrid;
begin
  TmpStringGrid := TStringGrid.Create(nil);
  TmpStringGrid.Rows[0] := Grid.Rows[r1];
  Grid.Rows[r1] := Grid.Rows[r2];
  Grid.Rows[r2] := TmpStringGrid.Rows[0];
  TmpStringGrid.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
var TmpStringGrid : TStringGrid;
begin
  ExchangeRows( StringGrid1, 2,1 );
end;

regards
mirek.
Avatar of koger

ASKER

Hmm, I think you misunderstand me Mirek, since TStingGrid is a descendant from TCustomGrid, you should be able to use all the functions from that object, MoreRow is just a single one, is it possible to use the other functions on TStingGrid
ASKER CERTIFIED SOLUTION
Avatar of mirek071497
mirek071497

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of koger

ASKER

if you say it's impossible then I will accept that as an answer.

However I wonder how to use the DeleteRow statement from the TCustomGrid, when you search the Delphi Helpfile it seems that only TCustomGrid has the DeleteRow procedure, can the statements at all be used, I'm sure it can, but perhaps you would be so very kind to tell me how :-)
I have now hdd crash. I can watch to delphi now. I am workin from linux lynx :(( however I willl return after two days here and I will explain more : Why and How ok ?