Click here to Skip to main content
15,886,815 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

Checkout this it may help you..
How to Add Items to a ListBox in Visual Basic.NET[^]

In C#:
C#
private void button1_Click(object sender, System.EventArgs e)
{
    listBox1.Items.Add(&amp;amp;amp;quot;Sally&amp;amp;amp;quot;);
    listBox1.Items.Add(&amp;amp;amp;quot;Craig&amp;amp;amp;quot;);
}

private void button2_Click(object sender, System.EventArgs e)
{
    listBox1.Items.Clear();
}
 
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