Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert string value to button.

Status
Not open for further replies.

jjjax64

IS-IT--Management
Apr 27, 2010
39
US
Hi, want to add buttons to a form and name them from data returned from SQL server but also add event handler for onClick of each button to be different. We currently can loop through a recordset and add these buttons but all have same onClick event handler. Thanks, Joe
 
Got it working in case it helps someone else:

Do While NextResult = True
Dim Button1 As New Button
Button1.Location = New Drawing.Point(2, 80 + i * 20)
Button1.TabIndex = i
Button1.TabStop = False
Button1.Text = "Open"
Button1.Tag = SQLReader.GetValue(1).ToString
LogIn.FormName = SQLReader.GetValue(1).ToString
AddHandler Button1.Click, AddressOf ClickButton
Controls.Add(Button1)
...
NextResult = SQLReader.Read()
Loop

-----------------------------------------------------

Private Sub ClickButton(ByVal sender As Object, ByVal e As EventArgs)

Dim frm As New Form

Dim formName As String = DirectCast(sender, Button).Tag.ToString
formName = [Assembly].GetEntryAssembly.GetName.Name & "." & formName

frm = DirectCast([Assembly].GetEntryAssembly.CreateInstance(formName), Form)

frm.Show()

Me.Hide()

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top