2017-02-27 18 views
1

我試圖顯示TDBGrid的單元格的空文本,而不更改字段的值,也不更改單元格的背景顏色。 我不知道這是正確的做法,但我已經使用OnDrawDataCell事件如下嘗試:如何使用TDBGrid繪製空單元格?

procedure TMyForm.MyGridDrawDataCell(Sender: TObject; 
    const Rect: TRect; Field: TField; State: TGridDrawState); 
var 
    Grid : TDBGrid; 
begin 
    inherited; 
    if(Field.FieldName = 'MYFIELD') then 
    begin 
    Grid := Sender as TDBGrid; 
    Grid.Canvas.FillRect(Rect); 
    end; 
end; 

放置一個斷點到事件之後,我發現它從未執行

回答

1

解決使用OnDrawColumnCell事件處理程序,而不是過時的OnDrawDataCell

由於documentation說:

待辦事項ñ不寫一個OnDrawDataCell事件處理程序。 OnDrawDataCell是 已過時幷包含在內以實現向後兼容。相反,寫一個 OnDrawColumnCell事件處理程序。

相關問題