Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


How do I format Display Text in a DBGrid (using multiple formats)?

How do I format Display Text in a DBGrid (using multiple formats)?

How do I format Display Text in a DBGrid (using multiple formats)?

I have a DBGrid which displays the following example columns:


Which displays in the grid for example:

1,Science,J Jones
2,Science,A Bones
3,Technology,N Harvey

However I want it to display in the DBGrid as depending on the Department in use as:

Sci-000001,Science,J Jones
Sci-000002,Science,A Bones
Tech-000003,Technology,N Harvey

The backend database looks like this:

I have a table called ASSIGNMENTS which contains the fields

Assignid integer (auto increment with new record)
DeptId integer
Teacher nvarchar(50)

I have a table called DEPT which contains the fields, the DisplayFormat is what is used to format the column depending on the department

DeptID integer
DeptName nvarchar(50)
DisplayFormat nvarchar(20)

These are two example records for Department

DeptName: Technology
DisplayFormat: Tech-%.6d

DeptName: Science
DisplayFormat: Sci-%.6d

I tried using OnGetText, which works fine when the column is set to only one format, thats no problem. What I cannot figure out is how to use multiple formats depending on the Department in use?

Thanks for any help on this

RE: How do I format Display Text in a DBGrid (using multiple formats)?

Considering it was made ​​a Join with the DEPT table to get DisplayFormat field, you can use code like the following in the event OnGetText:

CODE -->

if DisplayText then
    Text := Format(DataSet1DisplayFormat.AsString, [DataSet1Assignment.AsInteger])
    Text := DataSet1Assignment.AsString; 

Hope this help.


RE: How do I format Display Text in a DBGrid (using multiple formats)?

Hi imex,

That makes perfect sense, thank you for the quick reply.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close