我有 2 個不同來源的資料集 - 有些用于政府,有些僅用于組織。我需要以某種方式區分它們,比如讓一些專案加粗或不同的顏色。
我嘗試使用DrawItem事件,但無法弄清楚。
為了添加我使用的專案:
while not (cdDataset1.Eof) do
begin
if ((cdDataset1.fieldbyName('displayName').value<> '') and (cdDataset1.fieldbyName('TyypId').value=1280781)) then
begin
cxDBCheckListBox1.Items.Add.Text:= cdDataset1.fieldbyName('displayName').value;
end;
cdDataset1.Next;
end;
cdDataset1.First;
while not (cdDataset1.Eof) do
begin
if ((cdDataset1.fieldbyName('displayName').value<> '') and (cdDataset1.fieldbyName('TyypId').value=1243501)) then
begin
cxDBCheckListBox1.Items.Add.Text:= cdDataset1.fieldbyName('displayName').value;
end;
cdDataset1.Next;
end;
這部分效果很好。但是我可以使用欄位 TyypID 來區分 cxdbchecklistbox 嗎?它應該看起來像這樣(當然是復選框而不是專案符號):
- 重要選項1
- 重要的選項2
- 額外資訊選項1
uj5u.com熱心網友回復:
我找到了解決方案。首先添加標簽。需要 OnDrawItem 創建畫布:
//adding items to checklistbox where needed.
cxDBCheckListBox1.Items.Clear;
while not (cdDataset1.Eof) do
begin
if ((cdDataset1.fieldbyName('displayName').value<> '') and
(cdDataset1.fieldbyName('TyypId').value=28078)) then
begin
with cxDBCheckListBox1.Items.Add do
begin
Text:= cdDataset1.fieldbyName('displayName').value;
Tag := 1280781;
end;
end;
cdDataset1.Next;
end;
//Then on drawitem:
procedure TfmSample.cxDBCheckListBox1DrawItem(
Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
ACanvas: TcxCanvas;
AText: string;
ATextRect: TRect;
AGlyphWidth: Integer;
AListBox: TcxDBCheckListBox;
ACanvasFont: TFont;
AItemEnabled: Boolean;
AItemTag: Integer;
begin
AListBox := (Control as TcxDBCheckListBox);
ACanvas := AListBox.InnerCheckListBox.Canvas;
ACanvasFont := ACanvas.Font;
AItemTag := AListBox.Items[Index].Tag;
AItemEnabled := AListBox.Items[Index].Enabled;
case AItemTag of
1243501:
begin
ACanvasFont.Color := clBlue;
end;
1280781 :
begin
ACanvasFont.Style := [fsBold];
ACanvasFont.Color := clBlack;
end;
end;
ACanvas.Brush.Color := clWhite;
ACanvas.FillRect(Rect);
AText := AListBox.Items[Index].Text;
ATextRect := Rect;
ATextRect.Left := 20;
ACanvas.DrawTexT(AText, ATextRect, 0);
end;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/406490.html
標籤:
上一篇:無論輸入如何,BPL中的C#P/Invoked函式都回傳指向Delphi記錄的相同指標
下一篇:CreateEvent多個監聽器
