Solved

Use TCustomGrid with TStringGrid?

Posted on 1998-09-05
5
734 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

16 Experts available now in Live!

Get 1:1 Help Now