Topic: ComboBox multiple values

Hello all,

I have a table with customers which have ID, ShortCustName, LongCustName, address, ...
I would like to select from a combobox the ShortCustName and near the combobox to place a textbox or Label in which I should place the longCustName.

Could you please point me in the right direction?
Thank you.

Best regards,
Alin

Re: ComboBox multiple values

Hello,


It's possible using script, but you can show multiple field in the ComboBox this way, using the property FieldName, example:

{ShortCustName}  {LongCustName}

or even:

ShortName: {ShortCustName}  LongName: {LongCustName}

property FieldName

Specifies which column of the database table belongs to this component. You can specify multiple fields: {field1} {field2}

Dmitry.

Re: ComboBox multiple values

Hello Dmitry,

This is working just fine, thank you.
If you don't mind, could you please tell me how to do this by script?

I mean, select the customershortname in combobox and display the long Customer name into a textbox or label.

Thank you.

Best regards,
Alin

Best regards,
Alin

Re: ComboBox multiple values

Hello Alin,
This is one way you can select a shortname from the combobox and display the corresponding longname in an textbox.
procedure form1_ComboBox1_OnChange (Sender: string);
begin
  form1.edit1.text := sqlexecute('select longname from customers where id ='+ inttostr(form1.combobox1.dbitemid));
end;
Hope this helps,
Derek.

5 (edited by m.alin 2016-04-06 08:27:22)

Re: ComboBox multiple values

Hello derek,

It's working perfectly, thank you so much.
I still have another question, regarding my project.
I have a table named products (productId, productNo, ProductName,...) where I have more than 500 products.

To show them all in a combobox is not so difficult but I have a problem because I have to scroll to much to get the right ProductNo.

I want to put a textbox in the form and to enter the material number in this textbox field and then get the ProductID which will be then saved in the database.

My Products contains letters and numbers, so i get an error message "no such column" even if I checked several times and the name of the column in the table is right.

My Code is

Procedure frmProductDetail_txtProductNo_OnExit (Sender: string);
begin
           frmProductDetail.txtProdID.text := sqlexecute('SELECT id from products where ProductNo=' +VarToStr(frmProductDetail.txtProductNo.text);
end;

Am I writting something wrong here?
Do I have to treat the VarToStr in another way as IntToStr?

Thank you.
Best regards,
ALin

Best regards,
Alin

Re: ComboBox multiple values

Hello Alin,
Having products with a mix of letters and numbers shouldn't cause you to get that error message.
If your material number is a field in the products table, can you not just set your combobox to show the 2 fields (material number, product no') that you need and sort the combobox by material number.  Or is that what you are doing and it is still too much scrolling.
Alternatively, could you just use a search field (material number) and a tablegrid (standard MVD) rather than writing a script for it?
If you could attach your project, other users might be able to suggest different ways of achieving what you want - I'm sure there must be quite a few - LOL!
Derek.

Re: ComboBox multiple values

m.alin
Please check out these examples, how to search in ComboBox
http://myvisualdatabase.com/forum/viewtopic.php?id=1447

Dmitry.