Board index » delphi » Selectively editing tStringGrid cells (and related questions)

Selectively editing tStringGrid cells (and related questions)

1. I want the user to be able to edit only certain tStringGrid cells
(for example: all those in the scrollable area of column 1 and none in
column 2). What's the best approach?

2. Can I set the alignment of tStringGrid cells text differently (for
different cells)?

-Ted

 

Re:Selectively editing tStringGrid cells (and related questions)


Quote
In article <37703328.5693D...@home.com>, Ted Michon wrote:
> 1. I want the user to be able to edit only certain tStringGrid cells
> (for example: all those in the scrollable area of column 1 and none in
> column 2). What's the best approach?

Write code in the OnSelectCell event handler. It passes a CanSelect
parameter which you can set as appropriate. A warning though - if you
set the current cell in code, you have to be careful because setting the
Row and Col values results in two calls and if your halfway position
falls on a forbidden cell, you are scuppered (why do I remember this
<g>). A simple workaround though, is to have a simple boolean
controlling whether the OnSelectCell is active.

Quote
> 2. Can I set the alignment of tStringGrid cells text differently (for
> different cells)?

Yes, by ownerdraw.

 Mike Orriss (TeamB)
 (Unless stated otherwise, my replies relate to Delphi 4.03)
 (Unsolicited e-mail replies will most likely be ignored)

Re:Selectively editing tStringGrid cells (and related questions)


Quote
> 1. I want the user to be able to edit only certain tStringGrid cells
> (for example: all those in the scrollable area of column 1 and none in
> column 2). What's the best approach?

Use the OnSelectCell handler, as Mike suggests. But instead of simply
refusing to select a cell the user should not be able to edit you modify
the grids Options, of the cell should be editable you do a

  Options := Options + [goEditing];

If it should be read-only you do a  

  Options := Options - [goEditing];

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Re:Selectively editing tStringGrid cells (and related questions)


Peter-

Thanks. Your solution did the trick for me.

-Ted

Quote
"Peter Below (TeamB)" wrote:
> > 1. I want the user to be able to edit only certain tStringGrid cells
> > (for example: all those in the scrollable area of column 1 and none in
> > column 2). What's the best approach?

> Use the OnSelectCell handler, as Mike suggests. But instead of simply
> refusing to select a cell the user should not be able to edit you modify
> the grids Options, of the cell should be editable you do a

>   Options := Options + [goEditing];

> If it should be read-only you do a

>   Options := Options - [goEditing];

> Peter Below (TeamB)  100113.1...@compuserve.com)
> No e-mail responses, please, unless explicitly requested!

Other Threads