Solved

Use TCustomGrid with TStringGrid?

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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