When I customize any attribute of a cell's Layout, then when navigating and selecting cells, it won't show anymore the layout globally defined under CellAppearance.SelectedLayout for those cells.
I'm building a program where the user can customize the grid, changing cell fonts, font size, fill color, etc ... but then the customized cells selections won't be visible.
I basically took AdvStringGrid Demo asg51 and replaced the ASG by a TMSFNCDataGrid. In ASG, the selection layout overrides the customized cells settings, and these settings are preserved and shown after you unselect cells.
Thanks.
BTW,
Trying to set event OnSelectCell raised this error:
First of all, TAdvStringGrid & TTMSFNCDataGrid are not the same unfortunately. The signature of OnSelectCell events are not going to be compatible so you'll have to implement them by manually. The cells Layout property (Layouts) overrides all layout settings at global or column level, this is by design. You can change override the layout for one or more individual cells regardless of the settings in the OnGetCellLayout. In this case, you'll need the following code:
procedure TForm1.TMSFNCDataGrid1GetCellLayout(Sender: TObject;
ACell: TTMSFNCDataGridCell);
begin
if TMSFNCDataGrid1.IsCellSelected(ACell.Coordinate) then
begin
if (TMSFNCDataGrid1.FocusedCell.Column = ACell.Coordinate.Column) or (TMSFNCDataGrid1.FocusedCell.Row = ACell.Coordinate.Row) then
ACell.Layout.Assign(TMSFNCDataGrid1.CellAppearance.FocusedLayout)
else
ACell.Layout.Assign(TMSFNCDataGrid1.CellAppearance.SelectedLayout);
end;
end;
Should not access the cells Layout property inside of this event, either through TTMSFNCDataGridCellItemExtended.Layout or through ADG.Layouts[x,y].
If so, afterwards it'll raise lots of AVs navigating through grid and when it tries to open inplace editors.
The same errors are raised if I simply access Layout property inside of BeforeDrawCell
, AfterDrawCell or GetCellProperties.
Is there another approach where I could make cells content mantain it's individually customized aspects (Font.Name, Font.Size, Font.Style, TextAlign, VerticalTextAlign & TextAngle) , while applying some of the SelectedLayout properties, such as borders , Fill Color & Font Color ? Must consider that the cell layouts are beign controlled by the users, so I don't have predefined layouts for especific cell ranges.
Well the original solution can be extended by overriding the properties you want:
procedure TForm4.TMSFNCDataGrid1GetCellLayout(Sender: TObject;
ACell: TTMSFNCDataGridCell);
var
l: TTMSFNCDataGridCellLayout;
begin
if TMSFNCDataGrid1.IsCellSelected(ACell.Coordinate) then
begin
if (TMSFNCDataGrid1.FocusedCell.Column = ACell.Coordinate.Column) or (TMSFNCDataGrid1.FocusedCell.Row = ACell.Coordinate.Row) then
l := TMSFNCDataGrid1.CellAppearance.FocusedLayout
else
l := TMSFNCDataGrid1.CellAppearance.SelectedLayout;
ACell.Layout.Fill.Assign(l.Fill);
ACell.Layout.Stroke.Assign(l.Stroke);
ACell.Layout.Sides := l.Sides;
end;
end;
So right now, the situation for normal cells is they use the Layouts property completely, including the color. While for selected / focused cells they only use the font settings.
Is there something you miss using this approach? Let me know.
OK, access violations should not happen. Can you post your full code sample / project or if you don't want to share it publicly send it to me via a private message. Let's see how to properly solve this.
Now I see your point.
In your fisrt example, the entire ACell.Layout was beign assigned, and that wasn't desired.
Now in the second example, just borders, fill & stroke are assigned, so it's ok !
As in the first example the Layout was completely overridden, I thought it HAD to be completely overridden, and didn't notice ACell's Layout had incorporated by default the Cell's customized Layout.
You can choose to assign / override whatever properties you want. Still curious about the access violation though, should you have more information let me know.