?
Solved

Use TCustomGrid with TStringGrid?

Posted on 1998-09-05
5
Medium Priority
?
751 Views
Last Modified: 2008-02-26
How to use ex. MoveRow from TCustomGrid in a TStringGrid?
0
Comment
Question by:koger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 90 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

770 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