从OnDrawColumnCell:
一种OnDrawColumnCell事件处理程序可以调用DefaultDrawColumnCell 方法以指示数据识别网格写在 单元中的数据值。
使用DefaultDrawColumnCell这样。这是Delphi代码,但你可以很容易地转换它。
procedure TForm1.DBGridDrawColumnCell(Sender: TObject;const Rect: TRect;
DataCol: Integer; Column: TColumnEh;State: TGridDrawState);
begin
.....
DBGrid.Canvas.Brush.Color := clBlue;
DBGrid.DefaultDrawColumnCell(Rect,DataCol,Column,State);
....
更新
如何绘制DBGrid的活动行,无需设置dgRowSelect或dgMultiSelect。
- 我们需要获取当前行的顶部位置。
定义类的TDBGrid的是inheritant使CellRect,山口和行公众:
type
TMyDBGrid = class(TDBGrid)
public
function CellRect(ACol, ARow: Longint): TRect;
property Col;
property Row;
end;
function TMyDBGrid.CellRect(ACol, ARow: Longint): TRect;
begin
Result := inherited CellRect(ACol, ARow);
end;
现在,我们可以检查当前单元格的顶部OnDrawColumnCell事件:
procedure TMainForm.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var Col,Row : Integer;
begin
col := TMyDbGrid(DBGrid1).Col;
row := TMyDbGrid(DBGrid1).Row;
if (Rect.Top = TMyDBGrid(DBGrid1).CellRect(Col,Row).Top) and
(not (gdFocused in State) or not Focused) then
DBGrid1.Canvas.Brush.Color := clBlue;
DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;
朋友你好,谢谢你的回答。我已经在使用这种代码并且已经绘制了行。我需要知道的是如何仅绘制ACTIVE ROW,而不设置dgRowSelect或dgMultiSelect。换句话说,如何确定活动行(注意State.Contains(gdSelected)和grid-> SelectedRows-> CurrentRowSelected在这种情况下不起作用) – sgm
@sgm查看更新 –
没有聚焦的var! – sgm