is it possable to build a windows form from a DB at run time?

Posted on 2006-05-24
Last Modified: 2010-04-23
Populate the windows form with controls from a database query?
Question by:agent_xp
    LVL 8

    Expert Comment

    yes.....depending on how u want it....

    I have created one before for a client that created buttons and links from the database too..


    had 2 fields

    field1                  field2
    pc                      c:\

    and what would happen is my form would read the program and create 3 buttons on the form and when the user click on the button it would call what ever was in field2.

    user click google button and it would take them to google.

    a sample code for having a control created at runtime of the form and not by drag or drop would be...

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim b = New Button()
            b.Text = "Test Button"
            b.Size = New Size(100, 100)
            b.Location = New Point(0, 5)
        End Sub

    LVL 6

    Accepted Solution

    Create the Database structure as Follows

    Table : FormControlDetails


    1. ControlName           2. ControlText
    3. Left                        4. Top
    5. Container                6. ContainerObject
    7. Width                      8. Height
       etc. Columns as required by u

    At run time populate the data of the database (from the table specified) on initialise event
    and now start creating controls according to this data (at run time) on the Load event of the Form

    Thus u will be able to create the controls dynamically

    U can also create a Form Control in the same manner (in that case u have to choose the other events or Main Subs)

    LVL 8

    Expert Comment

    the code I provided does address the issue he/she was asking....

    If anything I would like to see points be given to someone....
    LVL 8

    Expert Comment


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now