• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 123
  • Last Modified:

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

Populate the windows form with controls from a database query?
0
agent_xp
Asked:
agent_xp
  • 3
1 Solution
 
bman9111Commented:
yes.....depending on how u want it....

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

example

had 2 fields

field1                  field2
google                www.google.com
yahoo                 www.yahoo.com
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.

example
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)
        Me.Controls.Add(b)
    End Sub




0
 
manchCommented:
Create the Database structure as Follows

Table : FormControlDetails

Columns

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)


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

If anything I would like to see points be given to someone....
0
 
bman9111Commented:
lol
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now