i have a flowlayoutpanel in my winform,
i want to add some button into the flowlayoutpanel when the form is loaded,
the number of button will depend on how many item(row) exist in my dataset
Private Sub temp_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Private Sub FlowLayoutPanel1_Paint(sender As Object, e As PaintEventArgs) Handles FlowLayoutPanel1.Paint
Dim btn As New Button
Dim table as datatable = Dataset11.Tables("ItemInfo")
For 'i think this will need a looping, but i have no idea how to write'
.Text = ?? 'text will be the itemName'
.Tag = ?? 'tag will be the itemPrice'
The problem here aside from adding a control is iterating from a
DataRows. So that is what you want to get to create the the buttons based on the content of your
Dim btn As New Button For Each drow As DataRow In table.Rows btn = New Button btn.Text = drow.Item("itemName").ToString btn.Tag = drow.Item("itemPrice").ToString FlowLayoutPanel1.Controls.Add(btn) Next
Also, you might take into consideration changing the event in which you are adding the controls in the
FlowLayoutPanel. You can use a
Form_Load event for example.