By retsehc - 4/24/2013
Private Sub foodorder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
countrooms()
dtgrid()
Dim btnArray(no) As System.Windows.Forms.Button
Dim xPos As Integer = 0
Dim yPos As Integer = 0
Dim n As Integer = 1
For i As Integer = 0 To no
' Initialize one variable
btnArray(i) = New System.Windows.Forms.Button
Next i
While (n <= no)
Dim brkln = n / 10
Dim rwidth = Panel1.Width / 10
With (btnArray(n))
.Tag = n + 1 ' Tag of button
.Width = rwidth - 1 ' Width of button
.Height = 60 ' Height of button
' Location of button:
.Left = xPos
.Top = yPos
' Add buttons to a Panel:
Panel1.Controls.Add(btnArray(n)) ' Let panel hold the Buttons
xPos = xPos + .Width ' Left of next button
' Write English Character:
.Text = DataGridView2.Rows(n - 1).Cells(0).Value.ToString
Dim newFont As New Font("Tahoma", 8, FontStyle.Regular)
.Font = newFont
.TextAlign = ContentAlignment.MiddleCenter
Dim btn = btnArray(n)
AddHandler btnArray(n).Click, AddressOf Me.ClickButton
If Math.Abs(brkln - Fix(brkln)) Then
Else
xPos = 0
yPos = yPos + 60
End If
n += 1
End With
End While
Label1.Visible = True
End Sub
Private Sub dtgrid()
Dim conn As New SqlConnection(ConnectString())
Dim cmd As New SqlCommand
Dim mydatatable As New DataTable
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
cmd.Connection = conn
cmd.CommandText = "select foodname,foodprice,category from globalfoodprice"
Dim lad As SqlDataReader = cmd.ExecuteReader()
mydatatable.Load(lad)
DataGridView2.DataSource = mydatatable
lad.Close()
End Sub
Private Sub countrooms()
Dim con As New SqlConnection(ConnectString())
Dim cmd As New SqlCommand
con.Open()
cmd.Connection = con
cmd.CommandText = "select count(*) as cnt from globalfoodprice where category='Soup'"
Dim lcd As SqlDataReader = cmd.ExecuteReader()
While lcd.Read()
no = Convert.ToString(lcd("cnt"))
End While
lcd.Close()
End Sub
***this code works well,but when i add another code like that in a 'sub' with a caregory of vegetable,it does not load. i add the 'sub' code at the bottom of my form load.please help sir,i dont know what to do with this
|
|