1 (edited by tcoton 2016-02-25 09:22:40)

Topic: How to display combobox original content when using scripts?

Hi MVDB fans,

I have very specific comboboxes where I filter the information to be listed using sql scripts but as soon as I release the list without changing anything, the default content of the combo does not come back. There is no problem when I change the value though.

What should I use to get the current value of the combo when I do not change anything?

below the details:



Form: Details
Combobox : ComboSimNr
foreignkey: Users.id_SIM
fieldname : SIMNo

Scripts:

var

sim: string;
SIMsstus: string;


// Auto-update id_status on change if current status is "In Stock"
procedure Details_ComboSimNr_OnChange (Sender: string);
begin
     SIMsstus:= SQLExecute('select id_status from SIM where SIM.id=' +sim);
     if SIMsstus = '3'
     then SQLExecute('update SIM set id_status=2 where SIM.id=' +sim);
end;


// procedure to display available numbers only when deployed or display current record by default
// SIM
procedure PopulateSIM_ComboBox(ComboBox: TdbComboBox; ShowNotUsed: boolean);
begin
    if ShowNotUsed then
    ComboBox.dbSQLExecute('SELECT SIMNo,'+
        'id FROM SIM GROUP BY SIMNo '+
        'HAVING (SELECT COUNT(*) FROM Users WHERE Users.id_SIM=SIM.id) = 0')
    else
    ComboBox.dbSQLExecute('SELECT SIMNo, id FROM SIM');
end;

//Populate filtered SIM Numbers in comboboxes
procedure Details_ComboSimNr_OnDropDown (Sender: string);
begin
    PopulateSIM_ComboBox(Details.ComboSimNr, True);
end;


// Reset Comboboxes on Details closure
procedure Details_OnClose (Sender: string; Action: string);
begin
    PopulateSIM_ComboBox(Details.ComboSimNr, False);
    PopulateVodanum_Combobox(Details.ComboBox_Vodanum, False);
    PopulateIMEI_Combobox(Details.ComboIMEI, False);
    Form1.Show;
end;


Edit: The post not being popular, I added a picture

http://myvisualdatabase.com/forum/misc.php?action=pun_attachment&item=1797

Post's attachments

Attachment icon combo_scripts.png 95.13 kb, 284 downloads since 2016-02-25 

Re: How to display combobox original content when using scripts?

Hello,


Very difficult to understand the problem without your project, please attach project or send it to support@drive-software.com with link on this topic.


Thanks.

Dmitry.

Re: How to display combobox original content when using scripts?

Email sent with the project.

Thanks for your support Dmitry!

Re: How to display combobox original content when using scripts?

For the sake of other people eager to use same kind of function, here is the answer:

Form: Details
Combobox : ComboSimNr
foreignkey: Users.id_SIM
fieldname : SIMNo

Scripts:

var

sim: string;
SIMsstus: string;
idSelected: integer;


// Auto-update id_status on change if current status is "In Stock"
procedure Details_ComboSimNr_OnChange (Sender: string);
begin
     SIMsstus:= SQLExecute('select id_status from SIM where SIM.id=' +sim);
     if SIMsstus = '3'
     then SQLExecute('update SIM set id_status=2 where SIM.id=' +sim);
end;


// procedure to display available numbers only when deployed or display current record by default
// SIM
procedure PopulateSIM_ComboBox(ComboBox: TdbComboBox; ShowNotUsed: boolean);
begin
    idSelected := ComboBox.dbItemID;
    if ShowNotUsed then
    ComboBox.dbSQLExecute('SELECT SIMNo,'+
        'id FROM SIM GROUP BY SIMNo '+
        'HAVING (SELECT COUNT(*) FROM users WHERE USERS.id_SIM=SIM.id) = 0 or SIM.id='+IntToStr(idSelected))
    else
    ComboBox.dbSQLExecute('SELECT SIMNo, id FROM SIM');
    ComboBox.dbItemID := idSelected;
end;

//Populate filtered SIM Numbers in comboboxes
procedure Details_ComboSimNr_OnDropDown (Sender: string);
begin
    PopulateSIM_ComboBox(Details.ComboSimNr, True);
end;


// Reset Comboboxes on Details closure
procedure Details_OnClose (Sender: string; Action: string);
begin
    PopulateSIM_ComboBox(Details.ComboSimNr, False);
    PopulateVodanum_Combobox(Details.ComboBox_Vodanum, False);
    PopulateIMEI_Combobox(Details.ComboIMEI, False);
    Form1.Show;
end;

It works very well, I just noticed that sometime, the filtering via SQL in the comboboxes does not work properly but a simple restart of the application fixed it.

Thanks a lot Dmitry, you saved my week! big_smile