I'm trying to show a user between 1-250 elements where they list out
OrderID | Description | Value | Multiplier | Value
1 Some Desc 20 1.0
20.00
2 Another 50 1.5
75.00
...
At any rate, I only want editing in Col-2 and Col-3... Where Col-4 is Calced
(like a spreadsheet).
Most of this was easy enough... Delphi's example of sorts answered that.
But, I cannot for the life of me figure out how to only let the user enter
numerics (i.e. 0-9, '.' and vk_Return)... I believe that the OnKeyDown and
OnKeyPress events are not being properly forwarded to the InPlaceEditor...
Or am I wrong, and there not supposed to be?... If not what good are the
Events in the Control if your just going to have it test for what I already
know will be assigned to a cell... Is there another method for handling
this???
Additionally, The OnGetEditText works fine.. That is I can take a string
previously formatted with spaces for effect with Format('%3.2f', [Value]),
Assign it to "Value" within the event and strip the spaces off... Which is
what I expected should happen... On the other hand, the on SetEditText Event
fires with every key press, not after editing is completed as the
documentation implies... Any Thoughts... Anyone? I suppose I could use the
event like an OnKeyPress and test the string each time.... Yuckkkk!
Please chance your poster name to something else than Borland.
> I'm trying to show a user between 1-250 elements where they list out
> OrderID | Description | Value | Multiplier | Value
>
> 1 Some Desc 20 1.0 20.00
>
> At any rate, I only want editing in Col-2 and Col-3... Where Col-4 is Calced
> (like a spreadsheet).
>
> Most of this was easy enough... Delphi's example of sorts answered that.
> But, I cannot for the life of me figure out how to only let the user enter
> numerics (i.e. 0-9, '.' and vk_Return)...
You do this using the grids OnKeyPress event:
procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
var
col: Integer;
begin
col := (Sender as tStringgrid).col;
if key = #13 then begin
...handle navigation to next cell and calc col 4 if 2 are 3 ok
end
else
case col of
2: if not (key in ['0'..'9',#8]) then key := #0;
3: if not (key in ['0'..'9',#8, DecimalSeparator])
then
key := #0;
end;
end;
The main problem with OnKeyPress for validation purposes is that the event
happens before the key is processed by the cell, so if you want to figure out
whether the cell will be valid if you let the key go through you have to tap
into the inplaceeditor, get its current Text, its SelStart and SelLength,
replace the "selection" in a string var to find out what the controls content
will be, validate that. If it fails you may want to swallow the key but that
makes life harder for the user since he now cannot edit the text in a way that
goes from valid value through an invalid one (e.g. with two decimal
separators) to a new valid one.
I tend to do the validation in an OnDrawCell handler, if the cell validates i
paint the cell and text normally, if it fails i paint the text white on a red
background to indicate invalid input. I do not force the user back to the cell
and also do not modify the cell in code, but while the grid contains an
invalid value the user can of course not submit it to whatever processing gets
done with it once input is complete.
Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
I was actually creating my own problem... You example clarified my
mistake... Thanks for the input... By the way, I'm not placing the moniker
"Borland" in my news reader (Outlook Express 5.0). As a matter of fact, I
haven't set anything at all up in it... I only use it to connect to your
news group... How does your news server handle non-entries... It must be
occurring on your end...
Thanks,
Mr. Borland?
Peter Below (TeamB) <10011...@compuXXserve.com> wrote in message
news:VA.00002f29.01ff0a9f@noname...
Borland wrote:
>
> Thanks Pete,
>
> I was actually creating my own problem... You example clarified my
> mistake... Thanks for the input... By the way, I'm not placing the moniker
> "Borland" in my news reader (Outlook Express 5.0). As a matter of fact, I
> haven't set anything at all up in it... I only use it to connect to your
> news group... How does your news server handle non-entries... It must be
> occurring on your end...
>
> Thanks,
>
--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
The fool escaped from paradise will look over his shoulder and cry
Sit and chew on daffodils and struggle to answer why?
As you grow up and leave the playground
Where you kissed your Prince and found your frog
Remember the jester that showed you tears, the script for tears. (Fish)
--