AbhiJeet
asked on
value set
need an expert solution for a typical problem as below;
In my form, i have a combo and an edit box. Combo has values as "YES" and "NO". If yes is selected then input into editbox is mandatory, and the text entered in the editbox shall be saved to database. Combo box values shall not be stored into database. Hence when the form reopens after saving the data, it shall query database for the values as entered into editbox, the query shall take other input parameters which are out of scope for this question.
If the record is found the editbox shall be populated with the value and combo box text shall be set to YES.
But combo box can take NO and also it can be left blank , hence how to set the text for combo as per user input when the form reloads after saving whether it is no or blank?
In my form, i have a combo and an edit box. Combo has values as "YES" and "NO". If yes is selected then input into editbox is mandatory, and the text entered in the editbox shall be saved to database. Combo box values shall not be stored into database. Hence when the form reopens after saving the data, it shall query database for the values as entered into editbox, the query shall take other input parameters which are out of scope for this question.
If the record is found the editbox shall be populated with the value and combo box text shall be set to YES.
But combo box can take NO and also it can be left blank , hence how to set the text for combo as per user input when the form reloads after saving whether it is no or blank?
ASKER
I need to set YES, NO or blank as per user input. Setting yes is not a problem as i mentioned that depends whether the edit box has value or not.
How to set No or blank as per user input.
How to set No or blank as per user input.
ASKER
is it possible to store user input for the combo into a disconected client dataset and retrieve later?
how to implement?
how to implement?
You did not get it. When you click save/post - check value of combo, if is yes then save value of edit to db, if is no then clear value in db.
... od form load open table/query ... If you set OnAfterScroll event, check on it if field is set, if yes then set combo value to yes.
procedure ....SaveToDB();
begin
table1.Edit; //or insert
if ComboBox1.Text = 'YES' then
table1.FieldByName('UserField1').AsString := Edit1.Text
else
table1.FieldByName('UserField1').Clear;
table1.Post;
end;
... od form load open table/query ... If you set OnAfterScroll event, check on it if field is set, if yes then set combo value to yes.
procedure ....table1AfterScroll(DataSet: TDataSet);
begin
if not DataSet.FieldByName('UserField1').IsNull then
begin
ComboBox1.ItemIndex := ComboBox1.Items.IndexOf('YES');
Edit1.Text := DataSet.FieldByName('UserField1').AsString;
end
else
begin
ComboBox1.ItemIndex := ComboBox1.Items.IndexOf('NO');
Edit1.Text := '';
end;
end;
ASKER
my question ws not understood clearly i hope.
Let me clarify once again:
The combo has values YES, NO, user can select either yes or no or leave as blank.
When it is selected as YES, edit is mandatory, in database i shall save the value.
I shall save the form and close. Then i shall open the form, then i shall get the value as stored in database and populate the edit.
Then if edit is not empty string, i am setting YES in combo, upto this point there is no issue.
But when NO is selected in combo, or it is left as blank and form is saved and reopened, how i can set the combo value as per user input?
Let me clarify once again:
The combo has values YES, NO, user can select either yes or no or leave as blank.
When it is selected as YES, edit is mandatory, in database i shall save the value.
I shall save the form and close. Then i shall open the form, then i shall get the value as stored in database and populate the edit.
Then if edit is not empty string, i am setting YES in combo, upto this point there is no issue.
But when NO is selected in combo, or it is left as blank and form is saved and reopened, how i can set the combo value as per user input?
"Yes", "No" and blank are 3 conditions
you have only given 2 conditions
if you have a record in the database it's yes.
otherwise it's either "No" or blank.
take the blank out is the obvious way to go.
simply put:
procedure SetCombo(RecordExists: Boolean);
const Vals: array[Boolean] of string = ('No', 'Yes');
begin
combobox.itemindex := Combobox.items.indexOf(Val s[RecordEx ists]);
end;
you have only given 2 conditions
if you have a record in the database it's yes.
otherwise it's either "No" or blank.
take the blank out is the obvious way to go.
simply put:
procedure SetCombo(RecordExists: Boolean);
const Vals: array[Boolean] of string = ('No', 'Yes');
begin
combobox.itemindex := Combobox.items.indexOf(Val
end;
ASKER
ID: 38839340 - This shall set combo as yes if record exists and no otherwise. But combo can left as blank also in which case also above code shall set the combo as NO.
what are the conditions and actions for "No" and "blank" ?
how do you set the combo blank after it has been filled with "Yes" or "No" ?
how do you set the combo blank after it has been filled with "Yes" or "No" ?
ASKER
when no is selected or no option is selected and combo is left as blank, the editbox shall be disabled and shall not be stored into db.
so basically "No" is the same as "blank" ?
ASKER
yes, and difficulty is to set the value in combo as no when no has been selected and blank when it has been left as blank by user.
To not set combobox when some field is not set:
combobox1.itemindex := -1;
add "No" and "Yes" to the items of the combo
set the style to csDropDownList
set the default upon start to "no"
itemindex = 0
then it can have only 2 values: either yer or no.
there is no point to allow for blank
as there is no difference between "no" and "blank"
set the style to csDropDownList
set the default upon start to "no"
itemindex = 0
then it can have only 2 values: either yer or no.
there is no point to allow for blank
as there is no difference between "no" and "blank"
ASKER
user has 3 choices, to select yes or no or leave blank. And after saving and reopening user needs the same value in the combo as entered, yes, no or blank.
ASKER
any solution please?
Hi,
An option could be to store blank choices in the database as empty strings an No choices as null. This way you could cover the three cases:
- the value is null, so the combobox should be No;
- the value is an empty string, so it should be Blank;
- otherwise it should be Yes.
Geo
An option could be to store blank choices in the database as empty strings an No choices as null. This way you could cover the three cases:
- the value is null, so the combobox should be No;
- the value is an empty string, so it should be Blank;
- otherwise it should be Yes.
Geo
ASKER
ID: 38845402: there are more than a dozen of this kind of combos in the form, hence cant store into db.
Any other workaround please?
Any other workaround please?
ASKER
no solution? can close without assigning any points?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I read multiple times too :-)
Without working sample (without connection to real db) from AbhiJeet it is hard to finish this.
Without working sample (without connection to real db) from AbhiJeet it is hard to finish this.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window