Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a combobox

Status
Not open for further replies.

ionutdinulescu

Programmer
Jun 11, 2002
59
GB
Hello !
I'm new to Delphi, but I have long experience in VB.
Tell me how can I populate a TComboBox with values of a field
In vb I use ListBox.ItemData to associate a value with it's corresponding ID in the table.
Is there a way to do this in Delphi, or I have to create a sepparate array ?

Can TDBGrid be used with TADODataSource?


Thanks
 
Code:
procedure DoSomethingUseful(Sender : TObject);
var 
  AValue : Integer;
begin
  ...
  MyComboBox.Items.AddObject('Displayed string', TObject(AValue));
  // AValue is now associated to 'Displayed string' object
  // Note: don't add -1 as object :)
  ...
  // Retrieving an object:
  AValue := Integer(MyCombobox.Items.Objects[MyCombobox.Items.Count - 1]);

  ...
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top