Hello,
My customer requests me to hide the selection (do not show any cells highlighted in blueish color) when the grid has no input focus. And to paint the selection again when the grid gains input focus (i.e. do not forget it while it is hidden).
I have not found any way to do this.
I even cannot see any way to set the selection to "none" (to implement myself hiding the selection in OnExit and showing it in OnEnter).
I expected a simple property like the HideSelection of TEdit in old Delphi 7...
Is there a way to implement this?
Thanks,
Peter
Hi,
Hello,
Thanks for the suggestion.
It has shown me the correct direction to go.
I still had two sub-problems:
1. assigning the whole layout has cancelled some other changed that I made using different means (e.g. centering some cells and right-aligning other cells). Of course, I could rearrange my code so that all the layout-related settings would happen in the OnGetCellLayout event.
But I decided not to change my code too much, so I just set those properties of the layout that are important to cancel the "selection look":
procedure TForm1.grGetCellLayout(Sender: TObject; ACol, ARow: Integer;
ALayout: TTMSFMXGridCellLayout; ACellState: TCellState);
var la:TTMSFMXGridCellLayout;
begin
if not TTMSFMXGrid(Sender).IsFocused then
begin
if ACellState in [csSelected,csFocused,csFixedSelected] then
begin
if ACellState = csFixedSelected then
la:=TTMSFMXGrid(Sender).GetDefaultFixedLayout.Layout
else
la:=TTMSFMXGrid(Sender).GetDefaultNormalLayout.Layout;
ALayout.Fill.assign(la.Fill);
ALayout.Stroke.Assign(la.Stroke);
ALayout.FontFill.assign(la.FontFill);
end;
end;
end;
So this sub-problem is solved for me.
2. Entering the grid by mouse click on a different cell than it is currently selected (but not visualized as selected because of our code) is not visualized nicely.
The problem is that the mouse down event triggers the focus and the grid is repainted (even if I delete the onEnter event, repainting on entering is apparently programmed somewhere "deeper" in the component) with the old selected cell shown. Only later the mouse up event makes the clicked cell selected and repaints the grid once more.
If you do it slowly (mouse down then wait for a second then mouse up), you can see clearly what happens. If you do it quickly (which is the usual way to do clicks) it is clearly visible that the grid is repainted twice and it is pretty ugly.
I have some ideas what to do, but all of them are pretty tricky (e.g. intercept mouse down and mouse up and then change the test to "not TTMSFMXGrid(Sender).IsFocused or FocusingClickIsStillDown", or maybe change the grid so that the cell selection is made on mouse down not on mouse up, or...)
Any better idea? Or has anybody solved a similar problem?
Thanks,
Peter
Hi,