简体   繁体   English

是否有与ItemIndex相对应的TDBComboBox?

[英]Is there a TDBComboBox equivalent that goes by ItemIndex?

In the helpfile entry for TDBComboBox, it says that the text of the selected option becomes the new value for the field. 在TDBComboBox的帮助文件条目中,它表示所选选项的文本成为该字段的新值。 Is there any similar control that goes by ItemIndex instead of text? 是否有任何类似的控件通过ItemIndex代替文本? (To represent an enumerated type, for example.) (例如,代表枚举类型。)

Try the TDBLookupComboBox. 尝试使用TDBLookupComboBox。 Check out the ListField, DataField and KeyField properties. 签出ListField,DataField和KeyField属性。

You can fill TDBComboBox items with numbers ('0, '1', '2', ...), but set DBComboBox1.Style to csOwnerDrawFixed and write OnItemDraw event. 您可以用数字('0,'1','2',...)填充TDBComboBox项,但将DBComboBox1.Style设置为csOwnerDrawFixed并编写OnItemDraw事件。 Something like this: 像这样:

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM