In the helpfile entry for TDBComboBox, it says that the text of the selected option becomes the new value for the field. Is there any similar control that goes by ItemIndex instead of text? (To represent an enumerated type, for example.)
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Try the TDBLookupComboBox. Check out the ListField, DataField and KeyField properties.
回答2:
You can fill TDBComboBox items with numbers ('0, '1', '2', ...), but set DBComboBox1.Style to csOwnerDrawFixed and write OnItemDraw event. 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;