----------------------------------------------------
ส่วนนี้เป็นการประกาศตัวแปรแบบ Public
Dim tbl As DataTable
Dim chkdatagrid As Boolean
----------------------------------------------------
Private Sub Frm_Load()
Headergrid()
AddDataToDatagrid(1)
End Sub
Private Sub AddDataToDatagrid(ByVal chkdata)
Dim r As DataRow
Select Case chkdata
Case 1
chkdatagrid = True
r = tbl.NewRow
tbl.Rows.Add(r)
Case 2
With dgvsalelist
If chkdatagrid = True Then
tbl.Clear()
End If
r = tbl.NewRow
r("proid") = txtserch.Text.Trim
r("pronames") = txtname.Text.Trim
r("prounit") = txtnumber.Text.Trim
r("pronumber") = txtprice.Text.Trim
r("proprice") = txtunit.Text.Trim
r("amount") = txtsum.Text.Trim
tbl.Rows.Add(r)
chkdatagrid = False
End With
End Select
End Sub
Private Sub Headergrid()
tbl = New DataTable
tbl.Columns.Add(New DataColumn("proid", GetType(System.Double)))
tbl.Columns.Add(New DataColumn("pronames", GetType(System.String)))
tbl.Columns.Add(New DataColumn("prounit", GetType(System.String)))
tbl.Columns.Add(New DataColumn("pronumber", GetType(System.Double)))
tbl.Columns.Add(New DataColumn("proprice", GetType(System.Double)))
tbl.Columns.Add(New DataColumn("amount", GetType(System.String)))
dgvsalelist.DataSource = tbl
With dgvsalelist 'เป็นการ set หัวของ datagrid
.Columns(0).HeaderText = "รหัสสินค้า"
.Columns(1).HeaderText = "ชื่อสินค้า"
.Columns(2).HeaderText = "หน่วยสินค้า"
.Columns(3).HeaderText = "จำนวนสินค้า"
.Columns(4).HeaderText = "ราคาขาย"
.Columns(5).HeaderText = "ราคารวม"
.Columns(0).Width = 90
.Columns(1).Width = 150
.Columns(2).Width = 100
.Columns(3).Width = 100
.Columns(4).Width = 100
.Columns(5).Width = 100
End With