Is there a TDBComboBox equivalent that goes by ItemIndex?

感情迁移 提交于 2019-12-06 08:31:17

Try the TDBLookupComboBox. Check out the ListField, DataField and KeyField properties.

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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!