是否存在与ItemIndex相同的TDBComboBox?

时间:2008-11-18 17:49:08

标签: delphi controls data-aware

在TDBComboBox的帮助文件条目中,它表示所选选项的文本成为该字段的新值。 ItemIndex而不是文本是否有任何类似的控件? (例如,表示枚举类型。)

2 个答案:

答案 0 :(得分:3)

试试TDBLookupComboBox。查看ListField,DataField和KeyField属性。

答案 1 :(得分:2)

您可以使用数字('0,'1','2',...)填充TDBComboBox项目,但将DBComboBox1.Style设置为csOwnerDrawFixed并写入OnItemDraw事件。像这样:

procedure TForm1.DBComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with (Sender as TDBComboBox).Canvas do
  begin
    FillRect(Rect);
    TextRect(Rect, Rect.Left+1, Rect.Top+1, MyValueDescriptions[Index]);
  end;
end;