Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I'm a beginner in vb.net, I need to save the (settings) or created buttons in runtime into my database so that the next time I run the application. the created buttons are still available.

How do I save the created buttons with its functions in runtime using my way of saving to database? any ideas?

My ideas was.. Saving the created buttons in runtime and then I'll loop the add handler at next formload so that I am only going to retrieve the buttons in my database and add its function during form load.

Sorry for the trouble of the way I'm saving the controls, someone told me to stick to what I know and create my application as fast as possible.

FYI: My Visual Basic coding knowledge isn't very strong, so I may require some explanations etc.

Connection String

VB
Dim dssettings As New DataSet   

Dim dasettings As New OleDbDataAdapter   

Dim sqlsettings, settings As String 


Public Sub connection()       

conMain.Dispose()       

conMain.ConnectionString = "Provider=MSDAORA.1;Data Source=xe;Password=testing;User ID=testing;Connection Timeout=20"       

conMain.Open()   

End Sub


Form1Connection()       

sqlsettings = "Select * From settings"       

dasettings = New OleDbDataAdapter(sqlsettings, conMain)       

dssettings.Clear()       

dasettings.Fill(dssettings, "settings")

End Sub




Saving Controls to Database either I'll use Addrow or Update

VB
Dim cb As New OleDb.OleDbCommandBuilder(dasettings)

dssettings.Tables("settings").Rows(1).Item("settings") = settings

dasettings.Update(dssettings, "settings")



Sample Create button

VB
Dim Choicebutton As New Button                       

With ChoiceButton                           

.Location = New Point(0, 380)                           

.Size = New Size(380, 50)                           

.Name = "test"                           

.Text = "test"                       

End With

            AddHandler Choicebutton.Click, AddressOf ChoiceButton_Click

Sample Added Handler

VB
Public Sub Choicebutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)       

Dim buttonThatWasClicked As Button = DirectCast(sender, Button)       

MessageBox.Show("You Clicked a Button with the text: " & buttonThatWasClicked.Text)   

End Sub
Posted

1 solution

You could try TableLayoutPanel and FlowLayoutPanel

Changing Layout Dynamically in Windows Forms[^]
TableLayoutPanel[^] & FlowLayoutPanel[^]
 
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