accessing TEdit in tmsfmxGrid

Hi,
Col 3 and 4 in my grid are TEdits
Accessing them from other parts of my code is not a problem. However when i fill my grid, I cant access them yet apparently?


    tmsGridCalc.RowCount := lFilteredList.Count + 1;
    for I := 0 to lFilteredList.Count -1 do
    begin
      lAmountCell.Col := 3;
      lAmountCell.Row := i+1;
      lNom := TBusinessObject(lFilteredList.Objects);
      tmsGridCalc.Cells[0,i+1] := lNom.Number;
      tmsGridCalc.Cells[1,i+1] := lNom.GetText;
      (tmsGridCalc.GetCellObject(lAmountCell) as TEdit).Text := '0';
    end;

The highlighted text gives an access violation. I guess I'm doing something wrong.

Hi, 


Please wrap your code with BeginUpdate and EndUpdate and afterwards call GetCellObject.

Kind Regards, 
Pieter
Hi Pieter, thanks for you quick reaction,
this still gives me the same problem 

   tmsGridCalc.BeginUpdate;
    tmsGridCalc.RowCount := lFilteredList.Count + 1;
    for I := 0 to lFilteredList.Count -1 do
    begin
      lNomencl := TBusinessObject(lFilteredList.Objects);
      tmsGridCalc.Cells[0,i+1] := lNom.Number;
      tmsGridCalc.Cells[1,i+1] := lNom.GetText;
    end;
    tmsGridCalc.EndUpdate;
    if tmsGridCalc.RowCount > 1 then
    begin
      lAmountCell.Col := 3;
      lAmountCell.Row := 1;
      (tmsGridCalc.GetCellObject(lAmountCell) as TEdit).Text := '0';
    end;

Regards,

Albert

Can you move the code that accesses the cell object in the OnApplyStyleLookup event?


Kind Regards, 
Pieter

No more access violation, but the Text '0' doesn't show either.

-Albert

Hi, 


We have investigated this here, and you can use the following code to accomplish this:

var
  c: TCell;
begin
  TMSFMXGrid1.BeginUpdate;
  TMSFMXGrid1.RowCount := 10;
  TMSFMXGrid1.ColumnCount := 10;
  TMSFMXGrid1.EndUpdate;
  TMSFMXGrid1.NeedStyleLookup;
  TMSFMXGrid1.ApplyStyleLookup;

  c.Col := 3;
  c.Row := 3;
  (TMSFMXGrid1.GetCellObject(c) as TEdit).Text := '0';
end;

Kind Regards, 
Pieter

Pieter Scheldeman2015-06-18 09:22:16

Thanks a lot, this solution works ! 

Kind regards,

Albert