![]() |
|
#1
|
|||
|
|||
|
I display the database 'id' field in my dbgrid.
Is it possible to display it as zero padded (for display purposes only in the dbgrid). eg,,, id 27, to display in the grid as 00000027 ======================================== A point waiting for the correct answer. thank you Jon |
|
#2
|
|||
|
|||
|
Make the ID field a Text, string or what ever your database would declare it as,
and write your own increment counter for it, then concat the leading zeros ot your number. Example //Auto Matic Incrementer while Found = false do begin if not QryID.Locate('ID',IntTostr(Count)]),[]) then begin Found:= True; tableID.AsString:= LeadingZeros(Count)+intToStr(Count); end else inc(count); end; ....... const MAXLENGTHOFNO 12; function TForm1.LeadingZeros(num:integer):string; var NumberofZerosToReturn:integer; counter:integer; zerosString:string; begin counter:=0; zerosString:=''; NumberofZerosToReturn:= MAXLENGTHOFNO - Length(inttoStr (num)); while NumberofZerosToReturn <> counter do begin zerosString:= '0'+zerosString; inc(counter); end; LeadingZeros:= ZerosString; end; Tell Me If You Found another way |
|
#3
|
|||
|
|||
|
I can't change the ID field, it must stay as it is.
======================================== A point waiting for the correct answer. thank you Jon |
|
#4
|
|||
|
|||
|
If you use BDE tables to connect to your database, it is possible.
By double clicking a BDE table component, the fields editor is opened. It shows the fields that are in the table. If it doesn't, click right on the fields editor and choose add fields. Select the Id field in this list. Now, the object inspectors shows the properties of this field. Set the displayformat property to '00000000' (without the quotes). This does the padding for you. Regards, Dennis |
|
#5
|
|||
|
|||
|
I'm using delphi 6, enterprise. I don't see that property?
======================================== A point waiting for the correct answer. thank you Jon |
|
#6
|
|||
|
|||
|
The DisplayFormat property is only available for numeric fields. Could you tell the datatype of the ID field?
Regards, Dennis |
|
#7
|
|||
|
|||
|
Right click on your table component and add all
your fields. Select the ID field and set the display format to 00000000 |
|
#8
|
|||
|
|||
|
I don't use a table component, everything is generated through adoqueries. I tried right click on the query and I get the fields editor, but then I can't add the fields because the query and connection is not active (I only activate at run time. Is there anyway to set the display format programmatically?
======================================== A point waiting for the correct answer. thank you Jon |
|
#9
|
|||
|
|||
|
I just made a temporary connection in the ide to get the fields. It works perfectly.
thanks ======================================== A point waiting for the correct answer. thank you Jon |
![]() |
| Thread Tools | |
| Display Modes | |
|
|