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!

Drop down lists in DBgrid ? 1

Status
Not open for further replies.

RonR51

Programmer
Apr 19, 2001
18
AU
I have a DBgrid where I would like to display some of the fields as drop down lists that present a string to the user but return an index number to the field in the attached paradox database table (I'm using the BDE).

I can do this by creating a lookup field in the grid that displays the records from another small table in the drop down box, but I have quite a few of these fields and it seems a bit messy to create many small database tables just to store a few options for drop down lists.

Is there a way to use hard coded array constants as the source data for the drop down lists or specify the list items at design time.

The DBRadioGroup seems to have the type of functionality I am looking for where you can enter the strings at design time, but the DBLookupCombo and the drop down in DBgrid doesn't.

Any suggestions.

RonR
 
To make a drop down list in a dbgrid:

Double click on the dbgrid
In the Column editor add the fields
Select the field you need
Select PickList in the Object Inspector
Fill in the strings and voila

Regards S. van Els
SAvanEls@cq-link.sr
 
Thanks for the reply to my question but it doesn't quite solve my problem completely as it returns the string to the attached field of the table whereas I want to return an integer.

The DBradiogroup has the facility where you define the strings at design time and also enter the corresponding values at design time that are returned to the table field. It is this type of facility I would like to use with the drop down lists but it seems like I will have to create small tables for each list where each table has a filed of strings and a field of return integer values.

regards

RonR

 
I did this thing a while ago so I cannot give you an exect answer, have to look it up, but the line of thinking is as follows:

Place 2 tables and 1 datasource on a form
connect the datasource to the maintable
Open de field editor and add the fields you need
Add also a new field, and define it as a look-up field
Connect this lookup field to your lookuptable

Set the datasource property of the look-uptable to datasource1 for synchronizing.

There are some details I do not remember right know, but try it out, while I look-up my sources

Regards
S. van Els
SAvanEls@cq-link.sr
 
Thanks for that advice. What you describe is exactly what I am doing at the moment and it does work very well and is also very flexible with regard to changing the contents of the drop down lists without re-compiling. I guess I was trying to avoid having to have a whole bunch of small tables (about 20) just to store drop down list data, some with only 2 or 3 items.

The other idea I am considering is presenting the main table in a DBCtrlGrid rather than a a DBGrid which will give me more flexibility with layout. I only need to display about 4 records at once so if I design the form carefully it might be a good solution.

Thanks again

RonR
ronr@arrb.com.au
 
Another solution for limiting the fields you are looking up, should be the use of a Tquery. There is an option to show for example a name, and entering a number, you just have to play with the properties of the look-up field.

Regards S. van Els
SAvanEls@cq-link.sr
 
To insert a lookup field in a dbgrid or dbctrl grid:
use the dbdemos alias for experimenting:

table1 --> orders
table2 --> employee
datasource1 --> table1

open field editor for table1
add orderno, empno, etc.

add new field:
name it emp_name
type : string
field type : look-up
key fields: empno

look up keys: empno
dataset: table2
result field: LastName

add a dbgrid or dbctrlgrid
open the columneditor and add:
orderno, emp_name etc.

This will do the trick


S. van Els
SAvanEls@cq-link.sr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top