Delphi Pages Forums  

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

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 11-18-2005, 12:20 PM
douglas douglas is offline
Senior Member
 
Join Date: Jul 2001
Posts: 7,695
Default DBGrid Question

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
Reply With Quote
  #2  
Old 11-18-2005, 05:43 PM
PGammerO PGammerO is offline
Junior Member
 
Join Date: Apr 2005
Posts: 20
Default RE: DBGrid Question

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
Reply With Quote
  #3  
Old 11-19-2005, 12:09 AM
douglas douglas is offline
Senior Member
 
Join Date: Jul 2001
Posts: 7,695
Default RE: DBGrid Question

I can't change the ID field, it must stay as it is.

========================================
A point waiting for the correct answer.

thank you

Jon
Reply With Quote
  #4  
Old 11-19-2005, 12:21 AM
questo questo is offline
Member
 
Join Date: Nov 2005
Posts: 85
Default RE: DBGrid Question

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
Reply With Quote
  #5  
Old 11-19-2005, 01:30 AM
douglas douglas is offline
Senior Member
 
Join Date: Jul 2001
Posts: 7,695
Default RE: DBGrid Question

I'm using delphi 6, enterprise. I don't see that property?

========================================
A point waiting for the correct answer.

thank you

Jon
Reply With Quote
  #6  
Old 11-19-2005, 02:13 AM
questo questo is offline
Member
 
Join Date: Nov 2005
Posts: 85
Default RE: DBGrid Question

The DisplayFormat property is only available for numeric fields. Could you tell the datatype of the ID field?

Regards,

Dennis
Reply With Quote
  #7  
Old 11-19-2005, 02:43 AM
davidj davidj is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,900
Default RE: DBGrid Question

Right click on your table component and add all
your fields.

Select the ID field and set the display format to
00000000
Reply With Quote
  #8  
Old 11-19-2005, 03:00 AM
douglas douglas is offline
Senior Member
 
Join Date: Jul 2001
Posts: 7,695
Default RE: DBGrid Question

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
Reply With Quote
  #9  
Old 11-19-2005, 03:11 AM
douglas douglas is offline
Senior Member
 
Join Date: Jul 2001
Posts: 7,695
Default RE: DBGrid Question

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
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 10:15 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.