此问题发现是一个共性
在DataGrid的OnCustomDrawCell中的代码按如下方法修改:
procedure TMainForm.DataGrid1CustomDrawCell(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TTreeListNode; AColumn: TTreeListColumn; ASelected, AFocused, ANewItemRow: Boolean; var AText: string; var AColor: Integer; AFont: TFont; var AAlignment: TAlignment; var ADone: Boolean);
var
I: Integer;
begin
if ASelected or AFocused then
exit ;
ACanvas.Font.Color := clBlack;
//原来根据某个字段值来设定颜色的方法,在分组后由于界面刷新机制的问题,就会乱套。所以改为判断Grid的某列的值来设定
for I := 0 to DataGrid1.ColumnCount - 1 do
begin
//循环取列找到相应的项(由于列允许移动位置和分组,所以不能固定),并判断其值
if (DataGrid1.Columns[I].FieldName = 'PROVIENCE') and
(SysUtils.trim(ANode.Strings[I]) = '北京') then
begin
AColor := clRed;
Break;
end;
end;
end;