I have a base form that contains a TcxGrid. Then, I have several forms inheriting from this base class, each one connected to a different dataset.
The grid displays the raw data, some fields in some tables contain rich text format.
What is happening is that these fields in the grid are displaying the rich text formatting instead of the value.
I need to be able to set at runtime, cxGrid1DBTableView1FieldName.Properties = RichText if FieldName is a field that contains RTF.
I know how to do that at design time, but I need help doing it at runtime.
How to set TcxGrid column's Properties at runtime.
Answers approved by DevExpress Support
Hello Ernesto,
You can see the A1097: How to set an item's Properties at runtime Knowledge Base article describing how to set an in-place editor to a Grid column at runtime.
Thank you. The article point me in the right direction.
In my case, so far, the only thing I need is to be able to display RTF fields.
This is what I did:
Add "cxRichEdit" to the uses clause.
procedure TForm1Dataset1AfterOpen(DataSet: TDataSet);
var
i: integer;
LColumn: TcxGridDBColumn;
LFieldName: string;
begin
cxGrid1DBTableView1.ClearItems;
cxGrid1DBTableView1.DataController.CreateAllItems();
//GetGridConfig; //This is a routine that reads a Grid's previously saved configuration (Visible, length, position of columns)
for i:= 0 to cxGrid1DBTableView1.DataController.ItemCount - 1 do
begin
if cxGrid1DBTableView1.Items[i].Visible then
begin
LFieldName:= TcxGridDBColumn(cxGrid1DBTableView1.Items[i]).DataBinding.FieldName;
if ( trim( LFieldName ) <> '' ) and ( Dataset.FieldByName( LFieldName ).DataType = ftMemo ) then
begin
cxGrid1DBTableView1.Items[i].PropertiesClass:= TcxRichEditProperties;
cxGrid1DBTableView1.Items[i].Options.IncSearch:= false;
cxGrid1DBTableView1.Items[i].Options.Filtering:= false;
cxGrid1DBTableView1.Items[i].Options.FilteringWithFindPanel:= false;
end;
end;
end;
end;