Solved

String grid column resize

Posted on 1998-09-01
7
1,962 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
[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
  • 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
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!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

691 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