?
Solved

String grid column resize

Posted on 1998-09-01
7
Medium Priority
?
1,992 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 150 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 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