定义activeCol :integer;procedure TForm1.dxDBGrid1Editing(Sender: TObject; Node: TdxTreeListNode; var Allow: Boolean); begin Allow := True; if (Node.Index =1) and (activeCol=0) then Allow := False; if (Node.Index =2) and (activeCol=3) then Allow := False; end;procedure TForm1.dxDBGrid1ChangeColumn(Sender: TObject; Node: TdxTreeListNode; Column: Integer); begin activeCol := Column; end;procedure TForm1.dxDBGrid1CustomDrawCell(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxTreeListColumn; ASelected, AFocused, ANewItemRow: Boolean; var AText: String; var AColor: TColor; AFont: TFont; var AAlignment: TAlignment; var ADone: Boolean); begin if (ANode.Index =1) and (AColumn.Index=0) then AColor := clRed; if (ANode.Index =2) and (AColumn.Index=3) then AColor := clRed; end;
如果要实现那个功能,最好还是不用Grid来显示。
颜色 CustomDrawCell中设置
ACanvas.SetBrushColor(clRed);
var Allow: Boolean);
begin
Allow := True;
if (Node.Index =1) and (activeCol=0) then Allow := False;
if (Node.Index =2) and (activeCol=3) then Allow := False;
end;procedure TForm1.dxDBGrid1ChangeColumn(Sender: TObject;
Node: TdxTreeListNode; Column: Integer);
begin
activeCol := Column;
end;procedure TForm1.dxDBGrid1CustomDrawCell(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxTreeListColumn;
ASelected, AFocused, ANewItemRow: Boolean; var AText: String;
var AColor: TColor; AFont: TFont; var AAlignment: TAlignment;
var ADone: Boolean);
begin
if (ANode.Index =1) and (AColumn.Index=0) then AColor := clRed;
if (ANode.Index =2) and (AColumn.Index=3) then AColor := clRed;
end;