Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > DB-Aware

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 07-08-2002, 10:15 AM
kardosi kardosi is offline
Senior Member
 
Join Date: Jul 2001
Posts: 121
Default Problem with editing text in TDBGrid...

Hi All!

How ca i guarantee, if the user type a text in a DBGrid column, don't can using any length of text? If i have column
that is NUMERIC TYPE, and the FIELD PHYSICAL length is 5,
the user can type in this field '12345678'... etc. But i need, that the user can type only '12345' !!! BUT HOW?
Another problem with this: If the field is NUMREC, but float
the user can type, like '1234.12.33.55.'... with multi '.'
it's abnormal... How can i solve this problem in the DBGrid?

Thanks for help...

Kardosi Bela
Reply With Quote
  #2  
Old 07-08-2002, 11:03 AM
HTML HTML is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,977
Default RE: Problem with editing text in TDBGrid...

Hello,

Double click you TTable make sure that the field is the fields editor list, if not add the field(add by right clicking in the listbox and click add fields).

Once you see the that numeric field in the fields editor box click it, then look at the object inspector, you'l see a property called CustomConstraint for that field, set the property to: FieldName<=99999 .FieldName is the Name of the field you should set. You can also set the MaxValue property to 99999 instead of CustomConstraint.

Also about '1234.12.33.55' that isnt a valid floating value so you should get an error when trying to post.

Hope thats what you wanted to know , Bye :-)
Reply With Quote
  #3  
Old 07-08-2002, 01:47 PM
kardosi kardosi is offline
Senior Member
 
Join Date: Jul 2001
Posts: 121
Default RE: Problem with editing text in TDBGrid...

Thanks HTML!

I have all fileds added it...
I set CustomConstraint to FIELD <= 99999, EditFormat to
#####, DisplayFormat to #####, MaxValue to 99999, BUT I CAN
TYPE longer number (like string) into the DBGrid cell, that contains the numeric field. The physical length in my
DBF is 5 for the field , and contains integer values... How can i do, that the user DO NOT ENTER longer number that
5 ?

Kardosi Bela
Reply With Quote
  #4  
Old 07-08-2002, 02:30 PM
HTML HTML is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,977
Default RE: Problem with editing text in TDBGrid...

Hello, Kardosi

Really if the max size is 5 for the field, then you would get a Value Out Of Bounds error, but you want to prevent more than 5 being typed in visually. Hmm, try setting the EditMask property

Table1TestTField.EditMask:='999999;0; ';

You can also try to embed a DBEdit into the Grid itself, and that way you have more control of user input.

Putting Components in Grids
by Alec Bergamini

http://www.sddug.slctnet.com/pres_c.htm

Or use a 3rd party DBGrid component, which already has such support. www.Torry.Net should have some.
Reply With Quote
  #5  
Old 07-08-2002, 03:15 PM
kardosi kardosi is offline
Senior Member
 
Join Date: Jul 2001
Posts: 121
Default RE: Problem with editing text in TDBGrid...

MANY THANKS, HTML!!!

So i need one more help with this problem...
If the value is integer, ALL OK !!!
But with floating point numbers i have problem:
If i set the mask to : '9999990.00;1, ', and user type number '1234567.89', ok, but (the number should be '12.33',
is the following problem (user type 1, than 2 than '.', than 3, than 3), i get the input string "12 .33". So this not a valid string to convert it to floating point ...
How can i solve this problem?

Kardosi Bela
Reply With Quote
  #6  
Old 07-08-2002, 05:08 PM
HTML HTML is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,977
Default RE: Problem with editing text in TDBGrid...

Hello,

That maybe a limitation when using Masks, you would have to embed a DBEdit in the DBGrid, which you will then have the flexebility of using the Key press events.

I myself use Woll2Woll's Infopower DBGrid, www.woll2woll.com ,Ive done exactely what you want by using their embedded wwDBEdit and keypress events. Try the Demo, it may have some other features you would really like.

An alternative, you could force the user to make changes in DB Aware controls that are outside the Grid?

There are some freeware DBGrid's on Torry.net that support embedded objects, such as http://gold.br.inter.net/demian/dbgrid.zip

If someother member has a suggestion, please dont hesitate to share your idea.

P.S
Im in no work for Woll2Woll , just a happy customer :-)
Reply With Quote
  #7  
Old 07-09-2002, 11:38 AM
HTML HTML is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,977
Default RE: Problem with editing text in TDBGrid...

Hello, Again.

Its amazing how sometimes you miss out on a idea, and then it pops up.

You may able to still use masks and prevent this error,

i get the input string "12 .33". So this not a valid string to convert it to floating point ...

On the BeforePost event of the TTable, you should take that new input string and remove all spaces,

S:String;

S:=StringReplace(Table1TEST.AsString,' ','', [rfReplaceAll]));

if S<>'' then begin
Table1.FieldValues['TEST']:=StrToFloat(S);
end;

Should work :-) Hope this helps.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:59 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.