Topic: Auto-fill a TextBox from a ComboBox

Hello everyone,

I’m working with My Visual Database and I need help with the following:

- I have a table called `Spec` with the fields:
  - `LevelClass`
  - `CustMassOfContam`
- I have a form called `Test` with:
  - A ComboBox `CB_LevelClass` for selecting a `LevelClass`
  - A TextBox `EDMassOfContamCust` where I want to automatically display the `CustMassOfContam` value corresponding to the selected `LevelClass`

My goal is:
- When selecting a value in the ComboBox, the TextBox should automatically display the corresponding value from the `Spec` table.

Does anyone know how to achieve this?

Thank you in advance for any guidance.

Re: Auto-fill a TextBox from a ComboBox

Hi

Example

Post's attachments

Attachment icon tt.zip 3.91 kb, 41 downloads since 2025-09-15 

Re: Auto-fill a TextBox from a ComboBox

thank you so much sparrow.   One more question, I am totally new using MVD and coding.   How did you populate the information on the table?  I tried to find the source but I couldn't


Thanks again.

sparrow wrote:

Hi

Example

Re: Auto-fill a TextBox from a ComboBox

Here is a link to a small guide. https://myvisualdatabase.com/forum/view … hp?id=2694

On the program's website, on the forum you can find various examples of programs to study. The forum itself is a treasure trove of information and opportunities.

Re: Auto-fill a TextBox from a ComboBox

Thanks, but what I mean is in your example you did not use a form in order to register the information in the table.  The data is alreay included in the table, and I would like to know how to have access to it.


sparrow wrote:

Here is a link to a small guide.

On the program's website, on the forum you can find various examples of programs to study. The forum itself is a treasure trove of information and opportunities.

Re: Auto-fill a TextBox from a ComboBox

Hi Luis, Sparrow,
What Sparrow has probably done is to use a program such as SQLiteStudio (free to download) which enables you to enter data directly into a table;  SQLite is the default database used by My Visual Database.
Many of us use programs such as SQLiteStudio as a quick way of populating a table with a couple of rows of sample data just so we can demonstrate a solution to a problem (such as your original question) rather than create additional forms - it simply saves a bit of time.
Another way (almost as quick when the requirement is very straightforward like yours) is to add a form and use an 'editable tablegrid' where you can enter data directly into the tablegrid rather than creating two forms (one to list the data via a tablegrid and one to create / edit the data (see attached).
Derek.

Post's attachments

Attachment icon tt 1.zip 336.58 kb, 42 downloads since 2025-09-16 

7 (edited by luisantafe 2025-09-21 07:44:15)

Re: Auto-fill a TextBox from a ComboBox

@derek and @sparrow, thank you both very much for your help so far; it has been extremely useful to me. I am facing a small issue that I haven’t been able to solve, and I would greatly appreciate your guidance.

In the attached file, I adapted the code. When I select a product’s color, its diameter should appear. However, if I happen to have two products with the same diameter, the code stops working and the information doesn’t show up in the text box. Could you please advise me on how to fix this?

Additionally, I would like to know how I can handle duplicate records, is there a function for this? Finally, how can I set the width of each column in a DataGrid?

I truly appreciate your time and support, and thank you again for your assistance.


Lois

Post's attachments

Attachment icon gt.zip 326.46 kb, 27 downloads since 2025-09-21 

Re: Auto-fill a TextBox from a ComboBox

Hi,
Have a look at the attachment that answers some of your points.
1.  I have changed your sql so that the correct diameter is now shown;  note that I have also used a calculated field (on the 'manguera' table) to enable the combobox in form1 to show not only the color but also the diameter so perhaps you don't even need form1.edit2 any more.
2.  There are a number of ways to check for duplicate records - the way I've done it is just one of them and there are probably advantages and disadvantages to the approach.
3.  Also note that in addition to fixing column widths in a tablegrid, you can also adjust widths dynamically according to the contents of an individual cell.
For comparison, I've also included a different approach in the attachment which uses a different data structure and the more traditional MVD approach of using 2 forms (one for the tablegrid list and one for the data maintenance);  with this approach, the script is only used for cosmetic purposes (the actual functionality is 'standard' MVD and doesn't require any coding).  Hopefully, this might give you some ideas.
Regards,
Derek.

Post's attachments

Attachment icon gt fixed.zip 782.79 kb, 43 downloads since 2025-09-21 

Re: Auto-fill a TextBox from a ComboBox

Derek, I truly appreciate the time, effort, and genuine interest you put into correcting my code and even suggesting such a brilliant alternative. Your guidance exceeded my expectations, and I am very grateful for your support.

I would also like to kindly suggest that you consider creating a virtual course for those of us who are eager to learn more about this program. I would be the first to enroll without hesitation. I am sure many others would benefit greatly from your knowledge and teaching.

Once again, thank you very much for your dedication and generosity.

L.

Re: Auto-fill a TextBox from a ComboBox

Hello luisantafe, hello Derek
As part of your training on various topics related to MVD, you will find the K245 blog very useful.
His articles are informative and relevant.
I had translated some of them into French, and I would like to continue translating the more recent ones, if K245 still agrees.
JB