Difference between ReadOnly and Fixed grid column

Hello,


as far as I can see the difference between a Fixed and a ReadOnly grid column is (beside the cell design) that a ReadOnly cell can get the focus and a Fixed cell not.

When navigating through the grid by Enter or Tab key from left to right, the cursor is jumping over a Fixed cell/column, but not over a ReadOnly cell/column. Is that wanted by design, and if so, what is the reason for this?

In fact there is even a difference between using the Tab key or the Enter key. When using the Enter key, the ReadOnly cell/cloumn is focused but the cursor is not moving further on the next Enter key stroke, but when using the Tab key, it is moving to the next cell/column. 


With best regards- Ulrich

This by design, a readonly cell can be selected but not edited, a fixed cell is not selectable nor editable.

I thought so, is the difference between using Tab key or Enter key also by design?

The Tab and Enter key have different behavior yes.

Sorry to insist on this cell navigation topic, but its elementary for my needs

Hi,



It's unclear what you want to see change to thus behavior?

Hello,


I just try to learn and understand the wanted default behaviour of the grid. I don't expect changes, just because I need them. I would like to navigate cellwise by the ENTER/TAB key and need cells/column which are readonly (skip) and cells/columns which are editable, but also skipped (no TabStop - but the user can edit it) Its for a medical billing application. 

So far the capabilities of the grid seems to be amazing and very much what I need. I'm just starting with the simple basic stuff - cell navigation :-)

Best regards - Ulrich

Hi, 


Thank you for your feedback.

In the other post we already provided a solution to skip readonly cells. Is this approach working for you?

Hello,


your provided solution (set cell to fixed and change cell layout to Appearance.NormalLayout) is working, except when using the Option.Bands.Enabled:= true, the bands are not painted inside the fixed cells.

Couldn't insert a screenshot here to show you

Before you provided your solution, my approach was

procedure TFormMain.FNCGridGetCellReadOnly(Sender: TObject; ACol, ARow: Integer; var AReadOnly: Boolean);
begin
  if(ACol = 6) then
  begin
    AReadOnly:= true;
    FNCGrid.Navigate(FNCGrid.NextSelectableColumn(ACol, ARow));
  end
end;   

and was wondering why this is not working, the cursor is just not moving. The same happens with 

procedure TFormMain.FNCGridSelectCell(Sender: TObject; ACol, ARow: Integer;  var Allow: Boolean);
begin
  if(ACol = 6) then
  begin
    Allow:= false;
    FNCGrid.EditCell(FNCGrid.NextSelectableColumn(ACol, ARow));
  end
end;    


Anyway, thanks for your help





The OnGetCellReadOnly is not the place to call a Navigate. The Navigate will not be executed as the grid has an update count during the call of those events.

Sorry, copy & paste error, it should be 


procedure TFormMain.FNCGridGetCellReadOnly(Sender: TObject; ACol, ARow: Integer; var AReadOnly: Boolean);
begin
  if(ACol = 6) then
  begin
    AReadOnly:= true;
    FNCGrid.EditCell(FNCGrid.NextSelectableColumn(ACol, ARow));
  end
end;  

But I guess the reason stays the same, because EditCell() implies a navigate...


What about the OnCellSelect() event? Same reason?



It's unclear why you want to control editing manually, if you want to directly edit a cell you should use Options.Mouse.DirectEdit := true

Try to describe the wanted grid behaviour :

While walking through the grid cells from left to right, the current cell is already in editing mode. Some cells/columns are read only (jump over on the next keystroke) other cells/columns are editable but normally jumped over because the contents will be filled automatically. What I wanted to archive is, to implement that logic inside the OnCellEnter event. 

I completely understand your suggested solution to set the cells/columns to fixed to archive the wanted behaviour that the cursor is jumping over to the next editable cell/column. I just try to understand why its not possible to implement the logic for jumping over readonly cells/columns by moving the cursor to the next wanted cell/column by code. 

I'm just asking to figure out whether this grid behaviour is by design or it should work different because of a bug. If its by design, I'm fine with it, or try to patch the grid for my needs.

With best regards

Its a bit clumsy, that I can't edit my previous message after posting it...


Anyway, for me its not really logic, that when setting a grid column to ReadOnly, that the cursor focus the ReadOnly cell when using the TAB key and move further on the next TAB keystroke, but just stays on the ReadOnly cell and not moving any further when using the ENTER key...

The behavior is by design, the Enter key will only jump to the next cell when a succesful edit operation has been performed. As the cell is readonly, editing is disabled, thus the next cell is not focused. The tab key has a different behavior because it acts as a selector and editor. When the cell is not editable, the tab key will jump to the next editable cell. If the cell is edited, the tab key handling stops editing and jumps to the next editable cell. To achieve the wanted behavior using either the tab or enter key, you could skip readonly columns by using the following code:


procedure TForm1.FormCreate(Sender: TObject);
begin
  TMSFMXGrid1.Columns[3].ReadOnly := True;
  TMSFMXGrid1.Options.Keyboard.TabKeyDirectEdit := True;
  TMSFMXGrid1.Options.Keyboard.TabKeyHandling := tkhNextCell;
  TMSFMXGrid1.Options.Keyboard.EnterKeyHandling := ekhNextColumn;
  TMSFMXGrid1.Options.Keyboard.EnterKeyDirectEdit := True;
  TMSFMXGrid1.Options.Mouse.DirectEdit := True;
end;

procedure TForm1.TMSFMXGrid1SelectedCell(Sender: TObject; ACol, ARow: Integer);
begin
  if FBlockSelection then
    Exit;

  if TMSFMXGrid1.Columns[ACol].ReadOnly then
  begin
    FBlockSelection := True;
    TMSFMXGrid1.SelectCell(TMSFMXGrid1.NextSelectableColumn(ACol, ARow));
    FBlockSelection := False;
  end;
end;

Its working, when I use EditCell() instead of SelectCell() I don't want just select the cell, it should switch to edit mode as soon as the cell becomes the current cell. Its all about to minimize the needed keystrokes to fill the grid.


Thank you for your patience and your help :-)

No problem! We will investigate if we can improve this behavior in the grid itself.