Click here to Skip to main content
15,885,954 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I create buttons in a app based on information in an access database in vb.net

The idea is that the app on form load, reads a database which tells it the button position, size, colour, link location, picture for button and button name. So that I can have a lot of buttons created on the form load event based on information in a database and then I can edit them if I want to buy amending the access database in the program.

Please can someone point me in the right direction -

Thank you
Posted
Comments
PIEBALDconsult 12-Feb-15 15:43pm    
Any way you like. What have you tried?
Member 10455358 12-Feb-15 17:10pm    
I have been able to set it up so that I have 20 buttons in a form. When you click on a button it does a search in a database for the button number and finds the URL field then opens that. however the code is very long and messy and the buttons are already created on the form.

So im looking for 2 things

1: to create buttons form data in a database when the form is open

2: when you click on a button it does a search in the database against the buttons name for the URL field in the database and then opens it.

Load data into datatable, then loop through the collection of data and create as many buttons as you wish ;)

For further information, please see:
Walkthrough: Editing an Access Database with ADO.NET[^]
ADO.NET Code Examples[^]
DataTable class[^]
DataTable.Rows Property[^]
Loading Access DB Table to Datatable[^]
 
Share this answer
 
This is the code I used in the end...

VB
Private Sub TABONEButtons()

        Dim buttonlabel
        Dim count As Integer

        count = Table1BindingSource.Count
        Timer1.Stop()



        Dim BTN As New Button

        'SET THE PROPERTIES OF THE CONTROL[BUTTON]

        buttonlabel = ButtonTextTextBox.Text

        BTN.Name = buttonlabel
        BTN.Text = buttonlabel
        BTN.Location = New Point(loc_control.X + 10, _
                                        loc_control.Y)
        BTN.Height = 100
        BTN.Width = 100
        BTN.FlatStyle = FlatStyle.Flat
        loc_control.Y += BTN.Height + 10
        BTN.BackColor = Color.FromName(ButtonColourTextBox.Text)
        BTN.ForeColor = Color.White
        BTN.TextAlign = ContentAlignment.BottomCenter
        BTN.Image = PhotoPictureBox.Image

        'CREATE THE EVENT HANDLER
        AddHandler BTN.Click, AddressOf myButtonHandler_Click
        'ADD THE NEW CONTROL[BUTTON] TO THE COLLECTION OF CONTROLS
        FlowLayoutPanel1.Controls.Add(BTN)



        '-------- count button code below ------------------------------------------------------------


        inc_control = inc_control + 1



        'move to next record---------------------------

        Table1BindingSource.MoveNext()

        'MsgBox("search has been run")



        'MsgBox(IDTextBox.Text)







        If inc_control < count Then TABONEButtons()




    End Sub

End Class
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900