How to store values from an SQL query into a ComboBox component?

眉间皱痕 提交于 2020-01-06 06:36:32

问题


I have a problem with the TComboBox component in Borland C++Builder 6.

In the ComboBox, I want to insert the result of an SQL query, eg:

ID  value
---------
1   one
2   two
3   three

I want to display the values of the value column to the user, e.g. one, two, three, but reference the values of the ID column.

Can anyone help me? Google did not say a lot about this to me.


回答1:


apologize forgot to put in some code

ComboBox1->AddItem("one", (TObject *) 1);
ComboBox1->AddItem("two", (TObject *) 2);
ComboBox1->AddItem("three", (TObject *) 3);

in my combobox the values one, two, three are displayed correctly now I would like to display the id of the currently selected item, e.g. 2

Label1->Caption = ???

and I do not know how to reference the ID values




回答2:


someone answered me on another forum but I would like to share this solution with you

I'm filling out the combobox component

cbx1->Items->Clear();
cbx1->AddItem("one",(TObject*)1);
cbx1->AddItem("two",(TObject*)2);
cbx1->AddItem("three",(TObject*)3);
cbx1->ItemIndex = 0;

read the ID of the selected item

int ID;
ID = (int)(cbx1->Items->Objects[cbx1->ItemIndex]);
ShowMessage(ID);


来源:https://stackoverflow.com/questions/51134551/how-to-store-values-from-an-sql-query-into-a-combobox-component

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