Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Formatting a Grid Cell or Grid Row
Mon, May 1 2017 9:57 AMPermanent Link

thomh

Hi Tim,

For a bound grid:

Is it possible to change the formatting of a grid cell based on the contents of another grid cell or another column in the underlying dataset?

If not, is it possible to do this for an unbound grid?

Thanks.

// Thom
Mon, May 1 2017 10:30 AMPermanent Link

thomh

It does seem to work for a bound grid.

I got this code in the OnCellUpdate event ('Flags' is another column in the dataset):

 if FData.Columns['Flags'].AsInteger = 1 then
 begin
   ACell.Font.Style.Bold := True;
 end
 else
 begin
   ACell.RefreshInterface;
 end;

And it does set the text for the relevant cell to bold.
Also when I move in the grid with up/down keys it works.

However, where it fails is when I position the selection cursor on the row which has the bold text
and highlight another row with the mouse. The result is that the row that was highlighted with the mouse
selection cursor also get the bold text.

// Thom
Mon, May 1 2017 1:45 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Thom,

<< For a bound grid:

Is it possible to change the formatting of a grid cell based on the contents of another grid cell or another column in the underlying dataset? >>

No, you cannot make any assumptions about the underlying dataset.  You can only use what is provided for the grid cell instance in terms of its contents.  The TGrid control is virtual and grid cells can be updated for all sorts of reasons, some of which have nothing to do with the underlying dataset.

<< If not, is it possible to do this for an unbound grid? >>

Same restriction.

Tim Young
Elevate Software
www.elevatesoft.com
Wed, May 3 2017 5:24 PMPermanent Link

Richard Harding

Wise Nutrition Coaching

thomh

<<Is it possible to change the formatting of a grid cell based on the contents of another grid cell or another column in the underlying dataset? >>

If the grid is bound to a dataset and the cell is an contains an index column then you can create a another "shadow" dataset, lookup the required values and change the formatting of the cell in the OnCellUpdate event.

It is limited in its use but I have found it useful.

Richard
Image