Public Items As List(Of selectitems) 'ประกาศแบบ Public เปลี่ยน Integer เป็น String หรือ อย่างอื่น
Public Sub btnpro_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpro.Click
'Try
If txtcusid.Text = "" Then
MessageBox.Show("กรุณาเลือกรหัสลูกค้าก่อนค่ะ", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtcusid.SelectAll()
txtcusid.Focus()
Exit Sub
Else
'initializeForm()
'ds.DataSource = dt
Dim f As frmcodepro = New frmcodepro
f.ShowDialog()
Me.Items = f.Item
If (f.Item.Count > 0) Then
' Headergrid()
For Each str As selectitems In Me.Items
' MessageBox.Show(str.Key & " " & str.named & " " & str.costs & " " & str.units & " " & str.srang
Dim r As DataRow
r = tbl.NewRow
'tbl.Rows.Add(r)
With DataGridView2
r = tbl.NewRow
r("key") = str.Key
r("named") = str.named
r("costs") = str.costs
r("qtys") = numzero
r("disc") = numzero
r("units") = str.units
r("srang") = str.srang
tbl.Rows.Add(r)
'chkdatagrid = False
End With
Next
End If
End If
' Catch ex As Exception
' End Try
End Sub
Code
Sub Headergrid()
'Dim strselect As String = "select s.s_pro as key,f.fgname as named,s.s_qty as qtys ,s.s_unit as units,s.s_cost as costs,s.s_disc as disc,s.s_amt as amt,s.s_range ans from PTsalediy s left join PTfg f on s.s_pro = f.fgpro where s.s_saleid = '" & txtsaleid.Text & "' "
'connection()
''dsdgrid.Clear()
''With da
'' .SelectCommand = New SqlCommand(strselect, conn)
'' .Fill(dsdgrid, "PTsalediy")
''End With
tbl = New DataTable
tbl.Columns.Add(New DataColumn("key", GetType(System.String)))
tbl.Columns.Add(New DataColumn("named", GetType(System.String)))
tbl.Columns.Add(New DataColumn("qtys", GetType(System.Double)))
tbl.Columns.Add(New DataColumn("costs", GetType(System.Double)))
tbl.Columns.Add(New DataColumn("units", GetType(System.String)))
tbl.Columns.Add(New DataColumn("disc", GetType(System.Double)))
tbl.Columns.Add(New DataColumn("amt", GetType(System.String)))
tbl.Columns.Add(New DataColumn("srang", GetType(System.String)))
DataGridView1.DataSource = tbl
With DataGridView1 'หัวของ datagrid
.Columns(0).HeaderText = "รหัสสินค้า"
.Columns(1).HeaderText = "ชื่อสินค้า"
.Columns(2).HeaderText = "จำนวน"
.Columns(3).HeaderText = "ราคา"
.Columns(4).HeaderText = "หน่วย"
.Columns(5).HeaderText = "ส่วนลด"
.Columns(6).HeaderText = "รวมเงิน"
.Columns(7).HeaderText = "Rang"
.Columns(0).Width = 105
.Columns(1).Width = 520
.Columns(2).Width = 100
.Columns(3).Width = 100
.Columns(4).Width = 65
.Columns(5).Width = 100
.Columns(6).Width = 100
.Columns(7).Width = 100
DataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
DataGridView1.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
DataGridView1.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
DataGridView1.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
DataGridView1.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
DataGridView1.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
DataGridView1.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
DataGridView1.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
DataGridView1.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(0).SortMode = DataGridViewColumnSortMode.NotSortable
.Columns(1).SortMode = DataGridViewColumnSortMode.NotSortable
.Columns(2).SortMode = DataGridViewColumnSortMode.NotSortable
.Columns(3).SortMode = DataGridViewColumnSortMode.NotSortable
.Columns(4).SortMode = DataGridViewColumnSortMode.NotSortable
.Columns(5).SortMode = DataGridViewColumnSortMode.NotSortable
.Columns(6).SortMode = DataGridViewColumnSortMode.NotSortable
.Columns(7).SortMode = DataGridViewColumnSortMode.NotSortable
.Columns(2).DefaultCellStyle.Format = "#,##0.00"
.Columns(3).DefaultCellStyle.Format = "#,##0.00"
.Columns(5).DefaultCellStyle.Format = "#,##0.00"
.Columns(6).DefaultCellStyle.Format = "#,##0.00"
.Columns(0).ReadOnly = True
.Columns(1).ReadOnly = True
.Columns(4).ReadOnly = True
.Columns(6).ReadOnly = True
.Columns(7).ReadOnly = True
.AlternatingRowsDefaultCellStyle.SelectionBackColor = Color.Gold
.AlternatingRowsDefaultCellStyle.SelectionForeColor = Color.Black
.DefaultCellStyle.SelectionBackColor = Color.Gold
.DefaultCellStyle.SelectionForeColor = Color.Black
.AlternatingRowsDefaultCellStyle.BackColor = Color.WhiteSmoke
DataGridView1.Font = New Font("Microsoft Sans Serif", 9, FontStyle.Regular)
.AllowUserToResizeRows = False
.AllowUserToResizeColumns = False
.AllowUserToAddRows = False
End With
End Sub
Sub Headergrid()
'Dim strselect As String = "select s.s_pro as key,f.fgname as named,s.s_qty as qtys ,s.s_unit as units,s.s_cost as costs,s.s_disc as disc,s.s_amt as amt,s.s_range ans from PTsalediy s left join PTfg f on s.s_pro = f.fgpro where s.s_saleid = '" & txtsaleid.Text & "' "
'connection()
''dsdgrid.Clear()
''With da
'' .SelectCommand = New SqlCommand(strselect, conn)
'' .Fill(dsdgrid, "PTsalediy")
''End With
DataGridView2.Font = New Font("Microsoft Sans Serif", 9, FontStyle.Regular)
.AllowUserToResizeRows = False
.AllowUserToResizeColumns = False
.AllowUserToAddRows = False
End With