looking for help. I want to have a form with up to around 20 buttons. I want their display names to be coming from an access database table of products i sell. I can connect the form to my database and get the first record in the table to display on the first button but when i do the same for the second button it just displays the first record again. Is there a way of pointing the button name to the second record in the table some how? I dolnt want to hardcode the product names into the code as abviously they may change in the future :-)
thanks in advance
Public Class f
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'LoftDataSet.Services' table. You can move, or remove it, as needed.
Me.ServicesTableAdapter.Fill(Me.LoftDataSet.Services)
'Loop through all the rows that are in the dataset
For Each dr As DataRow In LoftDataSet.Services.Rows
Dim btn As New Button 'Instantiate a button
btn.Text = dr("service_name").ToString 'UserName is a field in my Users Table
btn.Size = New Size(60, 40)
btn.Tag = dr("ID") 'Here we set the tag to the primary key (ID)
'Since we're using a flowlayoutpanel, we don't need to worry about setting the location property
FlowLayoutPanel1.Controls.Add(btn) 'Add the button to the flow layout panel
AddHandler btn.Click, AddressOf UserClick 'Here we give the button a handler for the click event
Next
End Sub
'Here we write our method for the click event of the button(s) we created
Private Sub UserClick(ByVal sender As Object, ByVal e As EventArgs)
'We set a filter to the binding source passing it ID=<and whatever is stored in the tag property>
ServicesBindingSource.Filter = "ID = " & DirectCast(sender, Button).Tag.ToString
End Sub
Aucun commentaire:
Enregistrer un commentaire