Solved

Use TCustomGrid with TStringGrid?

Posted on 1998-09-05
5
736 Views
Last Modified: 2008-02-26
How to use ex. MoveRow from TCustomGrid in a TStringGrid?
0
Comment
Question by:koger
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:mirek071497
ID: 1338683
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.
0
 

Author Comment

by:koger
ID: 1338684
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
0
 
LVL 3

Accepted Solution

by:
mirek071497 earned 30 total points
ID: 1338685
unfortunatelly no because

1. MoveColumn and MoveRow is in Protected statement.
2. between TStringGrid and TCustomGrid you have the TDrawGrid too.

Sorry for the reanswering, but
if you think so this is impossible than reject my answer twice and you don't hear about me more.
0
 

Author Comment

by:koger
ID: 1338686
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 :-)
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1338687
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 ?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
A short film showing how OnPage and Connectwise integration works.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now