我需要更改單元格的內容僅用于顯示。我在 DrawColumnCell 中執行此操作:
if Column.FieldName = 'UUID' then
begin
with (Sender as TDBGrid).Canvas do
begin
FillRect(Rect);
strTemp := (Sender as TDBGrid).DataSource.DataSet.FieldByName('UUID').AsString;
strTemp := RightStr(strTemp, Length(strTemp) - LastDelimiter('-', strTemp));
TextOut(Rect.Right - 2 - (Sender as TDBGrid).Canvas.TextWidth(strTemp), Rect.Top 2, strTemp);
end;
end;
UUID - 外觀為“SHRYU-5TRP0-RT-898-763523561294”。Оnly 需要顯示'763523561294'。
上面的代碼解決了這個問題,但如果你選擇這個單元格,原來的值和我的值和它們相互重疊被替換了。如何避免這種情況?
截屏
uj5u.com熱心網友回復:
DataSet 的基礎欄位的OnGetText()
事件是執行此操作的更合適的位置。使用持久欄位或在運行時連接事件。
procedure TForm1.FDMemTable1AGUIDGetText(Sender: TField; var Text: string;
DisplayText: Boolean);
Var
strTemp : string;
begin
if DisplayText then
begin
strTemp := Sender.AsString;
strTemp := RightStr(strTemp, Length(strTemp) - LastDelimiter('-', strTemp));
Text := strTemp;
end;
end;
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/503913.html