Re:Masking a TStringGrid
Quote
> I want to put a simple mask on what one enters in a TStringGrid - any
> character, but only 5 of them. I'm using the GetEditMask event by setting
> 'Value' as follows:
> Value := '!>ccccc;0; ';
> The mask works great, unfortunately when it's being read a VK_LEFT keydown
> is getting fired (I don't understand why)
The mask edit (TInplaceeditor derives from TCUstommaskedit) does that to
mask sure no characters belonging to the mask itself are selected.
Quote
>, and that kills me since I'm
> trapping VK_LEFT in the TStringGrid Keydown event and reacting to it. The
> end result is that when I press a key in my grid, focus jumps one cell left
> and nothing gets written in the original cell.
> Can anyone help my situation? I need to react to VK_LEFT so ignoring that
> is not an option. Perhaps there is a slicker way to mask a TStringGrid I
> could try?
Such a simple mask as yours could be easily implemented in an OnKeyPress
handler for the grid.
Type TGridCracker = Class( TStringgrid );
procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
If not (Key In [#8,#9]) Then // allow backspace & tab to fall through
With TGridCracker(Sender) Do
If Assigned( InplaceEditor ) Then Begin
if (inplaceeditor.gettextlen = 5) and
(inplaceeditor.sellength = 0)
then { cell filled, may want to move to next automatically }
key := #0;
End;
end;
Peter Below (TeamB) 100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!