TmsFMXGrid Firemonkey controls 'location'

Hi,

I set the CellClassType to a TCombobox for one column:

procedure TForm1.tmsGridCalcGetCellClass(Sender: TObject; ACol,
  ARow: Integer; var CellClassType: TFmxObjectClass);
begin
  inherited;
  if (ACol = 2) and (ARow > 0) then
    CellClassType := TComboBox;
end;

this works fine.

I added items and an onchange event to those comboboxes in GetCellProperties.

In the onchange event of the combobox I want to change and calculate some other cells in that row. However I can't seem to find a reliable way to know which col or row the combobox is located in.

I tried this, but the focused cell is usually not the cell the combobox is in:

procedure TForm1.CalcComboBoxChange(Sender: TObject);
begin
  tmsGridCalc.Cells[tmsGridCalc.FocusedCell.Col+1,tmsGridCalc.FocusedCell.Row] := 'test';
end;

So how do I know what cell my combobox is in ? 

Thanks in advance,

Albert

Hi, 


You can retrieve the cell with the following code:

procedure TForm1.ComboBoxChange(Sender: TObject);
var
  cl: TCell;
begin
  cl := TTMSFMXProtectedGrid(TMSFMXGrid1).GetCellByObject(Sender as TComboBox);
end;

It requires to define 

type
  TTMSFMXProtectedGrid = class(TTMSFMXGrid);

Kind Regards, 
Pieter

thanks for the solution.

How do I go the other way around, If I know the row and Col, how do i get the combobox.itemindex ?

thanks,

Albert



And a 3rd question, how can I disable editing for a single cell ?

Hi, 


You have the Sender, which can be casted to a TComboBox, so then you have the itemindex.
To disable editing for a single cell, you can implement the OnGetCellReadOnly event.

Kind Regards, 
Pieter

sorry, I think I was not clear enough. 
I don't have a sender, say for example i want to know the itemindex of the combobox in cell [2,2] when i click a TButton on my form. How do I cast cell[2,2] to a Combobox ?

And for disabling a Cell, I want to disable or enable editing for a specific cell in the Tcombobox.Onchange dynamically (depending on the itemindex).

Thanks in advance,
Albert

Hi, 


You can use the function TMSFMXGrid1.GetCellObject which returns a TControl based on a cell.
When the itemindex changes you could use a BeginUpdate and EndUpdate to trigger the OnGetCellReadonly which will then disable the cell based on the itemindex retrieved with the GetCellObject function.

Kind Regards, 
Pieter

Pieter Scheldeman2015-06-16 14:54:32