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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

only one value showing up in combo box

Status
Not open for further replies.

troyu

Programmer
Nov 21, 2000
185
CA
I have a table that has 4 records. I am trying to place a combo box within the form to return all records from the table in the combo box..

The problem I am having is only the 1st record is coming back.
 
dont know how you are trying to populate the combo.

try using a lop

while not reords.eof do
combo.add(record[x])
inc(x)
end;

not the exact code, but something like that should do it
 
dont know how you are trying to populate the combo.

try using a loop

while not reords.eof do
combo.add(record[x])
inc(x)
end;

not the exact code, but something like that should do it
 
Shouldn't you be able to return the values within the combo box without having to write any code?

I am trying to populate the combo box by using a TDBCOMBO box. I have set the Data Source and the TTable components already - Any ideas?
 
Are you using a TComboBox or a TDBComboBox? If you want to display something different than what will be stored in the database (like an enumerated field) then I'd suggest using the RxDBComboBox in the RXLib which gives you an items property and a values property.

DjangMan
 
Thanks, but I would rather not download any new components as of yet. I am using Delphi 1.0 as well...

I managed to insert a TDBLookupCombo box, and this appears to be pulling back the data from the table. Within the Object Inspector, I had to specify a Lookup Source, Field, and Display, and I have left the "Data Source" section blank. I hope that this is ok....
 
What you are probably looking for is a DBLookupComboBox. I'm not sure if that control is available in D1 or not. If not, you will probably have to populate the drop-down with code.

Most data aware controls are designed to show the current record in a dataset. The DBLookupComboBox and DBLookupListBox need two datasets, one to populate the dropdown and one dataset controls what value is selected from the dropdown.

Hope that helps!

TealWren
 
I am using the DBLookupComboBox now, and I am able to populate the box with values from a table without using code.

I guess the last question I have is within the OBject Inspector, I did not specify a Data Source, but I did specify a Lookup Source. Is this ok when I want to pull values from what the user selects from the combo box?
 
If you don't specify a datasource then a data-aware control won't work. It won't let you type anything or select anything from the drop-down. If you aren't editing a dataset with your data-aware control, then you will need to use a normal combo and populate it by hand.

TealWren
 
But it does let me select from the drop down. I am able to select a populate table value from the drop down box.

What I am planning to do is get the user to select from the drop down box, and then whatever value she selects, use that value to post to another table...
 
Hi Troyu,

It may be too late in terms of design but you might want to consider making your form not attached to the database directly. Use regular control and use underling code to reset text boxes, combo boxes, etc. to the values of the current record, validate user input, post and delete records.

It's more coding but it separates your interface from your programming logic which means that you don't have to fiddle with the eccentricities of DBLookupCombos (which drive me nuts X-) ). You can then use any kind of control to process the user's input and do any kind of validation before you allow the record to be added to the database.

It can be a pain the rump but the benefits are there for moving to later versions of Delphi later on since you can change the form without affecting your logic.

Good luck!

DjangMan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top