1

I have a delphi form with a cxgrid on it, the grid is connected to a query/datasource.

If a field in the database table is an Integer, is there anyway of me displaying the integer as a string on the cxgrid column?

e.g. 1 = January
     2 = February
     3 = March

and so on.

Thanks,

Sharpie
  • 373
  • 2
  • 15
  • 34

2 Answers2

2

Yes, there is such possibility.

Put TcxEditRepository component next go your grid. Double click on it, you should see the empty window with "Add..." button. Click it and from the list of available components select ImageComboBox.

Now, you need to edit Items property of this combo.

enter image description here

After filling up all rows go to your view (TcxGridDBTableView or TcxGridTableView) and pick the column which contains integer values. This column has a property called RepositoryItem. If you did everything correctly you should be able to select the repository item which you've created earlier (the ImageComboBox). After selecting it, your column should immediately display month names instead of numbers.

Wodzu
  • 6,932
  • 10
  • 65
  • 105
1

Other approach is to override cxGrid column OnGetDisplayText event. You could do something like that:

procedure TSomeForm.GetDisplayText(Sender: TcxCustomGridTableItem;
  ARecord: TcxCustomGridRecord; var AText: string);
var
    nVal : Integer;
begin
    nVal := ARecord.Values[Sender.Index];    
    case nVal of
    1: AText := "January";
    //and so on
    end;
end;
Ari0nhh
  • 5,720
  • 3
  • 28
  • 33