Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

topcat01

Programmer
Jul 10, 2003
83
0
0
GB
I have a DBGrid which displays the following example columns:

Assignment,Department,Teacher

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
 
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])
else
    Text := DataSet1Assignment.AsString;

Hope this help.

[URL unfurl="true"]http://www.imoveisemexposicao.com.br/imobiliarias-em-guarulhos[/url]
 
Hi imex,

That makes perfect sense, thank you for the quick reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top