Link to home
Start Free TrialLog in
Avatar of paulsinn
paulsinn

asked on

Can't get picklist to work in DBGrid

I've got a dataset in a Microsoft SQL server environment. A field in the dataset is of type integer and contains fixed values 0 and 1. 0 means the payment was cash 1 means a bill has to be sent. I want the 0's en 1's to be displayed as translated text in the grid. According to the manual this should be possible by setting the ButtonStyle to cbsAuto and enter the translate list in the  PickList property.

I've tried this over and over but the numbers keep appearing and not the text from the PickList.

The manual states that the Table Field has to be a lookup field. But the only lookup fields I can create needs another table.
Avatar of paulsinn
paulsinn

ASKER

Edited text of question
Do you want this field to be edited or is it just for display purposes?
PS. why not using a byte as field type? You only use 0 and 1! Regards, Zif.
Philipf
I just want to display.

ZifNab
I'm not using a byte value because the number of states might very well rise over the 256 boundary in the future. Besides where talking very small databases here!
Try This:

  Create a new calculated field of type string.(the size is completly up to you).  Then on the TTables OnCalcFields Event assign this new field a value based on the value of your interger field.

Below is what the TTables OnCalcFields event might look like.

procedure TForm1.Table1CalcFields(DataSet: TDataSet);
begin
  If Table1CashPay.Value = 0 Then
    Table1CashDesc.Value := 'Cash'
    Table1CashDesc.Value := 'Not Billed';
end;

Now if you don't want the users to see the integer field just set it's visible property to false.

I hope this helps.
 
 
phillipf

This probably will work but I don't want to be coding an endless if - then - else construction if more state arise. The anwer you gave doesn't solve the picklist problem. It creates a detour. Thanks anyway. I'm going to reopen the question for other experts.

Paul.
Would you have any objections to creating another table to be used to lookup these descriptions?  Since the number of states is going to be unknow (sorry I thought there were going to be only two) then this would probably be your best bet?
The issue isn't the lookup problem but why it won't work with the picklist as is documented in the manual. If I have to create a table for every lookup the number of tables will grow exponentionally!
philipf please read.

I earlier rejected Your answer on my problem. I've now come to the conclusion that that is the only way to do it. I've interpreted the Picklist wrong. I thought the Picklist would automatically translate info from the field to the picklist and visa versa but it doesn't. I think you're entitled to the points. Respond to this message and you'll get them.
ASKER CERTIFIED SOLUTION
Avatar of phillipf
phillipf

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial