Board index » delphi » 3 String Grid Questions!!!

3 String Grid Questions!!!

1st) Can the width of the fixed column be different from the width of the
other columns? If yes, how ?

2nd) I wrote the following source in the StringGrid MouseMove Event in order
to display some cell specific information on a status bar. But, I have two
problems. When I am moving the mouse over the fixed cells the text of those
cells is appearing in the next row and column also. When I click on the
scrollbars of the stringgrid everything returns to normal. The second
problem is when the mouse is moving on the area of the stringgrid that there
are no cells. I get a "grid out of index" exception. How can I block this
exception ?

procedure TPlaceAdvert.GridMouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
var
  r : integer;
  c : integer;
begin
  Grid.MouseToCell(x,y, c,r);
  if ((Grid.Row <> r) or (Grid.Col <> c)) then
  begin
    Grid.Row := r;
    Grid.Col := c;
  end;
  StatusBar.Panels[0].Text := Grid.Cells[0,r]+' -- '+Grid.Cells[c,0;
end;

3rd)Can I make a selection of multiple cells that are independend to each
other? I mean that they are not part of the same rect. I had in mind an
indicator that will show,by selecting the appropriate cells, where exactly I
move my mouse. That means that I need a routine that selects an row and an
independend column.

I know that I wrote a lot, so if you read this line i would like to THANK
YOU a lot for you patient and your help.

 

Re:3 String Grid Questions!!!


In <3996fc82_2@dnews>, Tassos Voulgaris wrote:

Quote

> 1st) Can the width of the fixed column be different from the width of the
> other columns? If yes, how ?

As far as I remember, the width of fixed columns is always DefaultColWidth, whereas the the width of each scrolling column is whatever you set its ColWidths property to.

Quote

> 2nd) I wrote the following source in the StringGrid MouseMove Event in order
> to display some cell specific information on a status bar. But, I have two
> problems. When I am moving the mouse over the fixed cells the text of those
> cells is appearing in the next row and column also. When I click on the
> scrollbars of the stringgrid everything returns to normal. The second
> problem is when the mouse is moving on the area of the stringgrid that there
> are no cells. I get a "grid out of index" exception. How can I block this
> exception ?

> procedure TPlaceAdvert.GridMouseMove(Sender: TObject; Shift: TShiftState;
>   X, Y: Integer);
> var
>   r : integer;
>   c : integer;
> begin
>   Grid.MouseToCell(x,y, c,r);

//  Delete from here  ===================
Quote
>   if ((Grid.Row <> r) or (Grid.Col <> c)) then
>   begin
>     Grid.Row := r;
>     Grid.Col := c;
>   end;

//  To here ===========================

Quote
>   StatusBar.Panels[0].Text := Grid.Cells[0,r]+' -- '+Grid.Cells[c,0;
> end;

You're trying to force the grid to select whatever cell is under the mouse (which probably confuses the hell out of it in the fixed rows and columns).  I think you can just delete the block that I've marked.

Quote
> 3rd)Can I make a selection of multiple cells that are independend to each
> other? I mean that they are not part of the same rect. I had in mind an
> indicator that will show,by selecting the appropriate cells, where exactly I
> move my mouse. That means that I need a routine that selects an row and an
> independend column.

Sort of, but I doubt that it would be easy.  You would need to keep track yourself of the cells you've 'selected' (for example in an array of TPoint),  and you'd need to write an OnDrawCell handler so you could draw your own highlighting of those cells.  The existing RangeSelect / Selected functionality only deals with a single contiguous block of cells.

Roger Morton
roger.mor...@dial.pipex.com

Re:3 String Grid Questions!!!


Tassos

Quote
> 1st) Can the width of the fixed column be different from the width of the
> other columns? If yes, how ?

Check out ColWidths[0]

Quote
> 2nd) I wrote the following source in the StringGrid MouseMove Event in
order
> to display some cell specific information on a status bar. But, I have two
> problems. When I am moving the mouse over the fixed cells the text of
those
> cells is appearing in the next row and column also. When I click on the
> scrollbars of the stringgrid everything returns to normal. The second
> problem is when the mouse is moving on the area of the stringgrid that
there
> are no cells. I get a "grid out of index" exception. How can I block this
> exception ?

A corrected version below.....
procedure TPlaceAdvert.GridMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
  r : integer;
  c : integer;
begin
  Grid.MouseToCell(x,y,c,r);
  if (r>=0) and (c>=0) then
  begin
    if ((Grid.Row <> r) or (Grid.Col <> c)) then
    begin
      Grid.Row := r;
      Grid.Col := c;
    end;
    StatusBar.Panels[0].Text := Grid.Cells[0,r]+' -- '+Grid.Cells[c,0];
  end
  else
    StatusBar.Panels[0].Text := '';
end;

Quote
> 3rd)Can I make a selection of multiple cells that are independend to each
> other? I mean that they are not part of the same rect.

No.  You have to use another custom grid component to do this.

Quote
> I know that I wrote a lot, so if you read this line i would like to THANK
> YOU a lot for you patient and your help.

You're welcome

Richard Teller

Other Threads