Link to home
Start Free TrialLog in
Avatar of richard_gar
richard_gar

asked on

vb.net Flow layout

I have the following code below that checks my database and then adds buttons to the FlowLayoutPanel. I want to limit the amount of buttons that fit on the flowlayoutpanel to 30 and then if there are more than 30 in the database add the others to flowpanellayout2.

I also want to add 3 buttons to the flowlayoutpanel at the end of my generated buttons how can I do this?
Dim con As New SqlConnection(My.Settings.Constr)
        con.Open()

        Dim cmd As New SqlCommand("SELECT * FROM tblCostumes WHERE master = '0'", con)
        Dim reader As SqlDataReader = cmd.ExecuteReader()

        While reader.Read()
            Dim btn As New Button
            btn.Name = "Button" & reader("id")
            btn.Width = 116
            btn.Height = 76
            btn.Tag = reader("name")
            btn.Text = reader("name")
            AddHandler btn.Click, AddressOf GetProductDetails
            FlowLayoutPanel1.Controls.Add(btn)
        End While

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of utter77
utter77

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of richard_gar
richard_gar

ASKER

My buttons are created dynamically so this solution would not work as I do not know how many fields there would be in my database as the user would add these.

Also my code would go on forever.
the buttons i add after the while-loop are the three buttons you wanted to add after the dynamic buttons.

i have added a counter and an if-statement in your while-loop that adds buttons to a different flowlayout if there is more than 30 buttons in the database
but how can I position the buttons after to be at a certain positioning?
add the buttons to a panel and positioning them there. then add the panel to the flowlayout.