Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,

I need your help to improve my developing skills.

I have data from database. When I run the form I need to create a button with name which is stored in db data.

Examble- I stored 1,2,3,4,5
When I run, I need to create a button in this name; also I need to make grouping.

http://www.ezeeburrp.com/images/screenshots/qsr.jpg[^]
Please go through this link. There you will get an idea what is my requirement.

There you can see button is arranged group-wise.

Thanks & regards,
reji
Posted
v3
Comments
[no name] 11-Apr-13 6:54am    
And your question/problem is what?
cycoreiiht 11-Apr-13 7:14am    
iwant to make button same like tht please sent me code in that software button crted through array ...all data stord in db when the form is open button crtng attomatticallyand its sorte in groupwise
[no name] 11-Apr-13 11:54am    
That is not a question or even a description of a problem. Post the code that you have written that demonstrates your problem and then clearly describe what the problem is. Also, read the FAQ for how to ask a question.
OriginalGriff 11-Apr-13 7:01am    
What have you tried?
Where are you stuck?

Additionally to the answer provided by Maciej Los you can simplify the grouping by adding the buttons to a FlowLayoutPanel instead of the Forms ControlCollection, which will then automatically arrange the controls according to your needs.

VB
FlowLayoutPanel1.Controls.Add(btn)
 
Share this answer
 
Comments
Maciej Los 11-Apr-13 17:33pm    
Good suggestion ;)
Have a look at below code. This is only an idea.

VB
Public Class Form1

    'to catch Click event ;)
    WithEvents oBtn As Button
    
    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Dim oDt As DataTable = Nothing
        Dim i As Integer = 0, btn As Button = Nothing

        'GetData() function reurns DataTable
        oDt = GetData()
        'enumerate through the collection of rows
        For i = 0 To oDt.Rows.Count - 1
            'create new button
            btn = New Button
            With btn
                .Parent = Me
                .Left = 8
                .Top = i * 24 + 8
                .Text = oDt.Rows(i).Item("MyIntegerColumn").ToString
                .Name = "Button" & i.ToString
                AddHandler btn.Click, AddressOf oBtn_Click
            End With
        Next

    End Sub

    'change to your needs ;)
    Private Function GetData() As DataTable
        Dim oDT As DataTable = Nothing, oRow As DataRow = Nothing
        Dim i As Integer = 0

        Try
            oDT = New DataTable("myIntegerData")
            oDT.Columns.Add(New DataColumn("MyIntegerColumn", GetType(System.Int32)))
            For i = 1 To 10
                oRow = oDT.NewRow()
                oRow.Item("MyIntegerColumn") = i
                oDT.Rows.Add(oRow)
            Next


        Catch ex As Data.DataException
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error")
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error")
        End Try


        Return oDT
    End Function

    Private Sub oBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles oBtn.Click
        MsgBox(sender.Name, MsgBoxStyle.Information, "Message")
    End Sub
End Class
 
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