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!

chnging values of the grid column on the fly

Status
Not open for further replies.

notlimah

IS-IT--Management
Nov 13, 2004
14
0
0
JM
i have a dbgrid with two columns basically when one of the column value is 'y' i want to translate that value in the in that specific column to 'yes' etc how would i acheive something like this?
 
You will use a "Calculated Field". How this is done depends on the data set connected to the grid. If it's a query of some sort, you'll probably need to make the translation in the query itself - I know this is true for TQuery, but I haven't worked with the ADO datasets.

If it's a table (i.e., TTable or similar) you would set up persistent fields (double-click on the table, right-click on the new form and select "Add All Fields"). You then add a new field with a field type of Calculated - in your case it would be a string field with a size of 3. Then, in the OnCalcFields event handler, you would put code similar to the following:
Code:
If Table1.FieldByName('MyField').AsString = 'y' then
  Table1.FieldByName('MyCalcField').AsString := 'Yes'
else if Table1.FieldByName('MyField').AsString = 'n' then
  Table1.FieldByName('MyCalcField').AsString := 'No';

-Dell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top