Private Sub DataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
If TypeOf e.Control Is ComboBox Then
If DataGridView1.CurrentCell.ColumnIndex = 0 Then
Dim cb As ComboBox = TryCast(e.Control, ComboBox)
'remove handler if it was added before
RemoveHandler cb.SelectedIndexChanged, AddressOf ColumnCombo1SelectionChanged
AddHandler cb.SelectedIndexChanged, AddressOf ColumnCombo1SelectionChanged
End If
End If
End Sub
Private Sub ColumnCombo1SelectionChanged(sender As Object, e As EventArgs)
Dim combo As ComboBox = CType(sender, ComboBox)
'ค้นหาข้อมูลที่นี่ โดยใช้ combo.Text เป็นเงื่อนไขค้นหา
End Sub
Private Sub ColumnCombo1SelectionChanged(sender As Object, e As EventArgs)
Dim combo As ComboBox = CType(sender, ComboBox)
'ค้นหาข้อมูลที่นี่ โดยใช้ combo.Text เป็นเงื่อนไขค้นหา
Dim dr As OleDbDataReader
Dim s As String = "select * from product where Pid = '" & combo.Text & "' "
dr = ExecuteReader(s)
While dr.Read()
dgv_pname.Text = dr.Item("Pname").ToString
End While
1 ไอดีน่าจะมีข้อมูลแถวเดียวไม่ต้อง While ก็ได้ครับ Code (VB.NET)
Private Sub ColumnCombo1SelectionChanged(sender As Object, e As EventArgs)
Dim combo As ComboBox = CType(sender, ComboBox)
'ค้นหาข้อมูลที่นี่ โดยใช้ combo.Text เป็นเงื่อนไขค้นหา
Dim dr As OleDbDataReader
Dim s As String = "select * from product where Pid = '" & combo.Text & "' "
dr = ExecuteReader(s)
dr.Read()
dgv.CurrentRow.Cells(1).Value= dr.Item("Pname")
dgv.CurrentRow.Cells(2).Value= dr.Item("bar")
dgv.CurrentRow.Cells(3).Value= dr.Item("bar")
dgv.CurrentRow.Cells(4).Value= dr.Item("bar")
dgv.CurrentRow.Cells(5).Value= dr.Item("bar")
dgv.CurrentRow.Cells(6).Value= dr.Item("bar")
dgv.CurrentRow.Cells(7).Value= dr.Item("bar")
Private Sub cal()
Dim i As Integer = 0
Dim total As Integer = 0
For i = 0 To dgv_SO.Rows.Count - 1
total = CDbl(dgv_SO.Rows(i).Cells(2).Value) * CDbl(dgv_SO.Rows(i).Cells(4).Value)
total = dgv_SO.Rows(i).Cells(5).Value
Next
tb_total.Text = total.ToString("##,##0.0")
End Sub
Private Sub DataGridView1_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
Try
DataGridView1(5, e.RowIndex).Value = CDbl(DataGridView1(2, e.RowIndex).Value) * CDbl(DataGridView1(4, e.RowIndex).Value)
Catch ex As Exception
End Try
'ใส่ Try ไว้ เผื่อค่าที่กรอกไปมีปัญหาไปงั้นๆแหละ
End Sub
Private Sub cal()
Dim i As Integer = 0
Dim total As Integer = 0
For i = 0 To dgv_SO.Rows.Count - 1
total = CDbl(dgv_SO.Rows(i).Cells(2).Value) * CDbl(dgv_SO.Rows(i).Cells(4).Value)
dgv_SO.Rows(i).Cells(5).Value = total
Next
tb_total.Text = total.ToString("##,##0.0")
End Sub
Private Sub cal()
Dim i As Integer = 0
Dim total As Integer = 0
For i = 0 To dgv_SO.Rows.Count - 1
total = CDbl(dgv_SO.Rows(i).Cells(2).Value) * CDbl(dgv_SO.Rows(i).Cells(4).Value)
dgv_SO.Rows(i).Cells(5).Value = total
MessageBox.Show(total) 'แค่อยากรู้ว่ามันคำนวณให้เรารึป่าว
Next
tb_total.Text = total.ToString("##,##0.0")
End Sub
Private Sub cal()
Dim i As Integer = 0
Dim total As Integer = 0
For i = 0 To dgv_SO.Rows.Count - 1
total = CDbl(dgv_SO.Rows(i).Cells(2).Value) * CDbl(dgv_SO.Rows(i).Cells(4).Value)
dgv_SO.Rows(i).Cells(5).Value = total
MessageBox.Show(CDbl(dgv_SO.Rows(i).Cells(2).Value) & vbCrLf & CDbl(dgv_SO.Rows(i).Cells(4).Value))
MessageBox.Show(total) 'แค่อยากรู้ว่ามันคำนวณให้เรารึป่าว
Next
tb_total.Text = total.ToString("##,##0.0")
End Sub
Private Sub cal()
Dim a As Integer = 0
Dim i As Integer = 0
Dim total As Integer = 0
For i = 0 To dgv_SO.Rows.Count - 1
total += CDbl(dgv_SO.Rows(i).Cells(2).Value) * CDbl(dgv_SO.Rows(i).Cells(4).Value)
dgv_SO.Rows(i).Cells(5).Value = total
Next
tb_money.Text = total.ToString("##,##0.0")
End Sub
Private Sub dgv_SO_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles dgv_SO.CellEndEdit
Try
dgv_SO(5, e.RowIndex).Value = CDbl(dgv_SO(2, e.RowIndex).Value) * CDbl(dgv_SO(4, e.RowIndex).Value)
Catch ex As Exception
End Try
End Sub
Private Sub ComboBox1_TextChanged(sender As Object, e As EventArgs) Handles ComboBox1.TextChanged
CalVAT()
End Sub
และ
Code (VB.NET)
Private Sub dgv_SO_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles dgv_SO.CellEndEdit
Try
dgv_SO(5, e.RowIndex).Value = CDbl(dgv_SO(2, e.RowIndex).Value) * CDbl(dgv_SO(4, e.RowIndex).Value)
CalVAT()
Catch ex As Exception
End Try
End Sub
แค่นี้ไม่ว่า User จะเปลี่ยน vat ตรง Combobox
หรือกรอกข้อมูลใน DataGridView
Private Sub dgv_SO_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles dgv_SO.CellEndEdit
Try
dgv_SO(5, e.RowIndex).Value = CDbl(dgv_SO(2, e.RowIndex).Value) * CDbl(dgv_SO(4, e.RowIndex).Value)
cal()'เพิ่มเข้าไปเพื่อให้ได้ยอดรวม เวลา เปลี่ยนข้อมูลใน datagrid
CalVAT()
Catch ex As Exception
End Try
End Sub