Topic: Default value of a textbox equal to a field
Hi everyone,
it is possible to put as default value of a TextBox what is written of a field of a table. The table has only one field and one record.
Thank you and greetings.
My Visual Database → General → Default value of a textbox equal to a field
Hi everyone,
it is possible to put as default value of a TextBox what is written of a field of a table. The table has only one field and one record.
Thank you and greetings.
Hi,
A couple of ways to do it.
1) use 'sqlexecute' and select the value from the table; as there can only ever be one row in your table, there is no need for a 'where' clause.
2) copy the value from the tablegrid cell (as there is only one row and one column, you can hard-code the cell location ([0,0]). Perhaps this is a slightly better option as it avoids making an extra call to the database.
Regards,
Derek.
Thanks derek,
studying your project I tried to adapt it to my needs but there is something I did not understand and it does not work well: I have to click twice on the button and the result does not remain permanently, would you be so kind as to look at the project that I have attached?
Thank you!
Hi Reteinformatica,
I downloaded your project but there is just a form - there is no script with it so I can't see the problem with clicking twice or the result not being saved. Nor is there a tablegrid.
Derek.
Thanks Derek,
In the meantime I have done many tests and only one thing I miss: Is there an instruction to automatically select the first line of a tablegrid so that if I press an associated button I should not first select the record from the Tablegrid?
Hi,
Yes, the instruction is in the script.
Remember that in MVD, the first column in the tablegrid starts at Column 0 and the first row in the tablegrid starts at Row 0 (this is what [0,0] in the line of script...... form1.tablegrid1.cells[0,0] refers to). It is the co-ordinates of the cell value that we want to use.
So, in the script, the line
if form1.tablegrid1.rowcount > 0 then form1.edit2.text := form1.tablegrid1.cells[0,0] else form1.edit2.Text:= ' ';
takes the contents of the cell in Column 0 and Row 0 in the tablegrid and copies the contents to form1.edit2.text.
Hope that's clear.
Derek.
Thanks Derek,
Unfortunately I understand little. I Put in an Annex A project that perhaps explains the matter better.
I put a button (Change) to change the value of the record of the Tablegrid but first you have to select the cell otherwise you receive the error ' Unable to certain the record ID '. I would like to hide this tablegrid but so you could not select the record before. So I would need that when the program starts the 0:0 cell is already automatically selected so that I can only click on the button without receiving the error.
To do also look at the script I created, I changed the textbox with a Label.
Thank you very much.
Hi,
Just add this line to the script
form1.tablegrid1.selectedrow := 0;
This places the cursor on the first row in the (hidden) tablegrid and tells the program which record ID to use (you can make the tablegrid visible to see how it has highlighted the row and then make it invisible again).
Derek.
Thanks Derek,
I understand something more and now something is advanced. The only thing I don't understand is why I don't work this statement
procedure Start_OnShow (Sender: string; Action: string);
begin
if Start.grDominio.rowcount = 0 then Start.Label18.caption := Start.grDominio.cells[0,0] else Start.label8.caption := 'Text Here --->' ;
end;
"Start" is a form.
Does not write "Text here" in the label
EDIT:
This is how I solved it:
If Start. grDominio. RowCount < > 1 then Start. Label18. Caption: = ' Text Here ---> ' ;
What's wrong with this education?
if Start.bNuovodominio.visible:= True then Start.Label18.caption := 'Qui va il nome del dominio, modificalo --->' ;
It says ' THEN execpted at 12:33'
What's wrong with this education?
if Start.bNuovodominio.visible:= True then Start.Label18.caption := 'Qui va il nome del dominio, modificalo --->' ;
It says ' THEN execpted at 12:33'
this is wrong - Start.bNuovodominio.visible: = True
Just delete the : after visible
this is true - Start.bNuovodominio.visible = True
this is full script
if Start.bNuovodominio.visible = True then Start.Label18.caption := 'Qui va il nome del dominio, modificalo --->'
Thanks Ivan,
so I don't get errors but the instruction doesn't work or the caption of laberl doesn't become "Qui va il nome del dominio, modificalo --->" but it's empty.
Below is the total code of the script:
procedure Start_OnShow (Sender: string; Action: string);
begin
if Start.grDominio.rowcount <> 1 then Start.Label18.caption := 'Qui va il nome del dominio, modificalo --->' ;
end;
procedure Start_grDominio_OnChange (Sender: string);
begin
if Start.bNuovodominio.visible = True then Start.Label18.caption := 'Qui va il nome del dominio, modificalo --->' ;
if Start.grDominio.RowCount = 1 then Start.bNuovodominio.visible := False else Start.bNuovodominio.visible := true;
Start.grDominio.selectedrow := 0;
Start.Label18.caption:= sqlexecute('select NomeDominio from Dominio');
Start.Label18.font.size:= 10
end;
begin
end.
EDIT:
I put the istruction on the bottom and so it seems to work
procedure Start_grDominio_OnChange (Sender: string);
begin
if Start.grDominio.RowCount = 1 then Start.bNuovodominio.visible := False else Start.bNuovodominio.visible := true;
Start.grDominio.selectedrow := 0;
Start.Label18.caption:= sqlexecute('select NomeDominio from Dominio');
Start.Label18.font.size:= 10
if Start.bNuovodominio.visible = True then Start.Label18.caption := 'Qui va il nome del dominio, modificalo --->' ;
end;
begin
end.
How do you add more content for a condition? If I understand the language for the scripts is Delphi, I tried to search but I didn't find anything.
For example "if 'condition' then text1.text = something AND text2.text = something else".
I tried with "and", "&" and "&&" but it doesn't work.
EDIT:
OK, I found it
if 'condition' then
begin text1.text = something;
text2.text = something else";
end;
My Visual Database → General → Default value of a textbox equal to a field
Powered by PunBB, supported by Informer Technologies, Inc.
Theme Hydrogen by Kushi