6

I would like to create an iOS App, with a fixed StringGrid. Every cell of this thing should only accept numeric values. For this I want to set the KeyboardType to vktNumberPad...but so far have not found a point of entry for this. Does anyone here have a clue on how to do this?

OK, so following Mikes hint I started to use my own column class.

TNumEditCell = class(TEdit)
end;
TNumberColum = class(TStringcolumn)
private
  function CreateCellControl: TStyledControl; override;
end;

And here comes the baffling part:

function TNumberColum.CreateCellControl: TStyledControl;
begin
  result := TNumEditCell.Create(Self);
  TNumEditCell(result).KeyboardType := vktNumberPad; // <- is undeclared!! What?!
  TNumEditCell(result).OnChange := DoTextChanged;
end;

Our good friend the compiler does not know what vktNumberPad is. Not even if I point him to it with a telephone pole FMX.Types.TVirtualKeyboardType(vktNumberPad). I guess I'm doing something wrong :(

Final edit: Indeed I did something wrong, as Peter pointed out. So with the code above and Peters hint everything works. Ummm...how do I finish this question?

Sherlock70
  • 564
  • 10
  • 24
  • For tedit, you can set the KeyboardType in the designer. Can't you do that with the tstringgrid? – Argalatyr Jun 18 '13 at 12:44
  • Nope, not as simply as with the TEdit. At least I could not find the property. – Sherlock70 Jun 18 '13 at 14:32
  • 1
    A grid cell is simply a TEdit so should be no problem but you'll need a custom column class so you can set it in CreateCellControl - http://monkeystyler.com/guide/Custom-Grid-Columns – Mike Sutton Jun 18 '13 at 19:17
  • @Sherlock70, have you tried to use a normal TEdit component with vktNumberPad? For me the VirtualKeyboard is always the same regardless which would point to a bug in the IFMXVirtualKeyboardService Interface. – Peter Jun 18 '13 at 21:21
  • @PeterVonča, TEdit with vktNumberPad works fine in the same App. BUT I'm using the demo version of X4...could that be the reason why my latest efforts are fruitless? – Sherlock70 Jun 19 '13 at 07:10
  • @Sherlock70, compiler doesn't know about vktNumberPad because you aren't addressing it correctly. use : `TNumEditCell(result).KeyboardType := TVirtualKeyboardType.vktNumberPad;` – Peter Jun 19 '13 at 08:45
  • @PeterVonča: D'uh! Silly me, now everything works fine. Thanks! – Sherlock70 Jun 19 '13 at 11:25

2 Answers2

2

Compiler doesn't know about vktNumberPad because you aren't addressing it correctly. use : TNumEditCell(result).KeyboardType := TVirtualKeyboardType.vktNumberPad

Peter
  • 2,977
  • 1
  • 17
  • 29
0

Just go to de column properties and in Column style select Currency column, or Float Column, depending on the type of column will be the kind of Keyboard showsen.