Solved

String grid column resize

Posted on 1998-09-01
7
1,898 Views
Last Modified: 2010-05-18
How can I detect when a column in a string grid has been resized in Delphi 3.
0
Comment
Question by:nhoj
  • 3
  • 2
  • 2
7 Comments
 
LVL 2

Expert Comment

by:333
ID: 1338354
Hi,
there is onDrawCell event. But it occurs whenever the contents of a grid cell need to be redisplayed. So it occurs not just when the column or row has been resized, but also when cell or row has been selected, scrolled etc. There are also ColWidthsChanged and RowHeightsChanged methods. They're called when the row or column has been resized. If you use the RxStringList from RxLibrary, there is onColumnSized and onRowSized events.

AP
0
 

Accepted Solution

by:
clopez earned 50 total points
ID: 1338355
It is very simple to detect when a Column is resized.  There is a dinamic procedure on the base component that is executed each time you resize a column.  Overriding it you can launch a notify event.  So you just have to create a new component and register it.  Do it as follow

1.- Create a unit with the following content:

unit NewStringGrid;

interface

uses
  Classes, Grids;

type
  TNewStringGrid = class(TStringGrid)
  private
    fOnColWidthChange:TNotifyEvent;
    procedure ColWidthsChanged; override;
  published
    property OnColWidthChange:TNotifyEvent read fOnColWidthChange write fOnColWidthChange;
  end;

procedure Register;

implementation

procedure TNewStringGrid.ColWidthsChanged;
begin
  inherited;
  if assigned(fOnColWidthChange) then fOnColWidthChange(Self);
end;

procedure Register;
begin
  RegisterComponents('Samples', [TNewStringGrid]);
end;

end.

2.- Add it to the user library or where you wan't and build it.

You will find the TNewStringGrid component under the samples page.  Use it assigning the OnColWidthChanged event.


0
 
LVL 1

Author Comment

by:nhoj
ID: 1338356
Thanks clopez

It works, I can now detect column resizing, but I need to know
which cloumn is being resized. Is this possible ?

nhoj
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 2

Expert Comment

by:333
ID: 1338357
I think you can use the MouseToCell method. There is simple ex. (use it with OnColWidthChange event):

procedure TForm1.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  Column, Row: Longint;
begin
  StringGrid1.MouseToCell(X, Y, Column, Row);
  if Column=0 then begin
   {the row Row was resized}
  end;
  if Row=0 then begin
   {the column Column was resized}
  end;
end;

AP
0
 

Expert Comment

by:clopez
ID: 1338358
I was trying to do so, but the component doesn't give any information about which was the column resized.  

My best idea so long is to keep track of then last change and check on the event;

interface

  TForm1 = class(TForm)
    StringGrid1: TNewStringGrid;
    procedure FormCreate(Sender: TObject);
    procedure OnColWidthChange(Sender: TObject);
  private
     LastSizes:array[0..ncols] of integer;
  public
     { Public declarations }
  end;

implementation

procedure TForm1.FormCreate(Sender: TObject);
var Count:Integer;
begin
   for Count:=0 to StringGrid1.ColCount-1 do
      LastSizes[Count]:=StringGrid1.ColWidths[Count];
end;

procedure TForm1.OnColWidthChange(Sender: TObject);
var Count:Integer;
     Found:Boolean;
begin
   Count:=0;
   Found:=False;
   while (Count<StringGrid1.ColCount) and not found do
      if LastSizes[Count]=StringGrid1.ColWidths[Count] then
         inc(Count)
      else
         Found:=True;
   if Found then
   begin
      LastSizes[Count]:=StringGrid1.ColWidths[Count];
//   The colum resized was "Count"
//  .........
   end;
end;
0
 
LVL 2

Expert Comment

by:333
ID: 1338359
As I said, use MouseToCell method. The Row and Column specifies row and column of grid, on which mouse button was pressed. When you resize row or cell, you press mouse button and MouseToCell returns column and row that was resized.
0
 
LVL 1

Author Comment

by:nhoj
ID: 1338360
Thanks chaps, thats all I need to know.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
build html 5 client that connect to indy Tidtcpserver 3 395
find a node in VST 2 68
how to update exe applicatio from internet ? 6 76
Twebbrowser add css to the header 3 24
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…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

785 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