QurbanDurrani
asked on
DBComboBox help
Hi Experts,
I have a form which has a DBGrid and a whole bunch of other components like DBEdit, DBRadioGroup, DBLookUpComboBox and DBComboBox. All these components point to the same table in the Database. As you select different records in the Grid, all the components get the corresponding values.
The DBComboBox1 points to the field 'Report' in the table. The field 'Report' is an integer field and currently only have the values 0,1 and 4. 0 stands for Reportdisabled, 1 stands for ReportEnabled and 4 stands for ReportInsiteonly.
I can get the DBComboBox1 to display 0,1 and 4. I can also click on the dropdown, select a different value and it is saved to that particular field.
1) What I want to do is for the DBComboBox1 to display Reportdisabled, ReportEnabled and ReportInsiteonly instead of 0,1 and 4?
2) Also when I select lets say 'ReportEnabled', It should save 1 in the field for that particular record?
I might have put in a little too much explaination, but I hope it helps understanding the question.
I have a form which has a DBGrid and a whole bunch of other components like DBEdit, DBRadioGroup, DBLookUpComboBox and DBComboBox. All these components point to the same table in the Database. As you select different records in the Grid, all the components get the corresponding values.
The DBComboBox1 points to the field 'Report' in the table. The field 'Report' is an integer field and currently only have the values 0,1 and 4. 0 stands for Reportdisabled, 1 stands for ReportEnabled and 4 stands for ReportInsiteonly.
I can get the DBComboBox1 to display 0,1 and 4. I can also click on the dropdown, select a different value and it is saved to that particular field.
1) What I want to do is for the DBComboBox1 to display Reportdisabled, ReportEnabled and ReportInsiteonly instead of 0,1 and 4?
2) Also when I select lets say 'ReportEnabled', It should save 1 in the field for that particular record?
I might have put in a little too much explaination, but I hope it helps understanding the question.
this is what's called a lookupcombo
you want to display a text and this is translated to a value in code
this lookupcombobox has a listsource, listindex and listfield property
you need to set up a datasource and query/table
this new query/table needs to read from a table containing the values ReportDisabled, ReportEnabled and ReportSiteOnly and id 0, 1, 4
so your table for reportstates would be
CREATE TABLE REPORTSTATES (
ID NUMBER(10) NOT NULL,
DESCR VARCHAR2(100) NOT NULL);
ALTER TABLE REPORTSTATES ADD (CONSTRAINT PK_REPORTSTATES PRIMARY KEY (ID));
INSERT INTO REPORTSTATES (ID, DESCR) VALUES (0, 'Report Disabled');
INSERT INTO REPORTSTATES (ID, DESCR) VALUES (1, 'Report Enabled');
INSERT INTO REPORTSTATES (ID, DESCR) VALUES (2, 'Report Disabled');
dsReportStates: TDataSource;
qryReportStates: TQuery; // select * FROM reportstates;
lookupcombobox
Datasource -> as your combobox
Datafield -> as your combobox
ListSource -> dsReportStates;
ListField -> Descr
ListIndex -> Id
dsReportStates.Dataset -> qryReportStates
you need to open the qry first
you want to display a text and this is translated to a value in code
this lookupcombobox has a listsource, listindex and listfield property
you need to set up a datasource and query/table
this new query/table needs to read from a table containing the values ReportDisabled, ReportEnabled and ReportSiteOnly and id 0, 1, 4
so your table for reportstates would be
CREATE TABLE REPORTSTATES (
ID NUMBER(10) NOT NULL,
DESCR VARCHAR2(100) NOT NULL);
ALTER TABLE REPORTSTATES ADD (CONSTRAINT PK_REPORTSTATES PRIMARY KEY (ID));
INSERT INTO REPORTSTATES (ID, DESCR) VALUES (0, 'Report Disabled');
INSERT INTO REPORTSTATES (ID, DESCR) VALUES (1, 'Report Enabled');
INSERT INTO REPORTSTATES (ID, DESCR) VALUES (2, 'Report Disabled');
dsReportStates: TDataSource;
qryReportStates: TQuery; // select * FROM reportstates;
lookupcombobox
Datasource -> as your combobox
Datafield -> as your combobox
ListSource -> dsReportStates;
ListField -> Descr
ListIndex -> Id
dsReportStates.Dataset -> qryReportStates
you need to open the qry first
ASKER
Thanks to both for your responses thus far.
Well I wish Issackhazi was right. I was looking for a simple solution like that one.
Geert Gruwez, I know I could use a DBlookupcombobox, but I did not want to create another table.
Is there a way to avoid creating another table?
Well I wish Issackhazi was right. I was looking for a simple solution like that one.
Geert Gruwez, I know I could use a DBlookupcombobox, but I did not want to create another table.
Is there a way to avoid creating another table?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you could use the VirtualTable from www.devart.com
it's an in memory table
and behaves like a normal table, excellent for small lookup tables.
it's an in memory table
and behaves like a normal table, excellent for small lookup tables.
a TClientDataset would do as well i guess
yep, Geert, alike memTable would be the most elegant method for my eyes
meikl ;-)
meikl ;-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Greet and Kretzschmar,
Thanks a bunch to both of you for excellent answers. Right before you guys answered, I was able to use a JvDBComboBox in the desired manner without any extra coding. However, as soon as I get some time I would like to revisit this and try both of yours solutions. By the way JvDBComboBox is a pain because there are no help documents available.
Thanks again to both of you.
Thanks a bunch to both of you for excellent answers. Right before you guys answered, I was able to use a JvDBComboBox in the desired manner without any extra coding. However, as soon as I get some time I would like to revisit this and try both of yours solutions. By the way JvDBComboBox is a pain because there are no help documents available.
Thanks again to both of you.
1. Display member
2. value member
You will have to give the meaninful names in the display member and the value member contains the corresponding code ie 1 0 or 4