เกี่ยวรึป่าวที่ผมใช้ ComboBox จากProductID แล้วมันไม่อัพเดท คิวรี่ก้อเหมือนกัน เพื่อนผมใช้ Text มันอัพเดทอะครับ
ข้างล่างนี้ โค้ดที่ใช้ได้คับ
Code (VB.NET)
Private Sub btnUpdate_Click(sender As System.Object, e As System.EventArgs) Handles btnUpdate.Click
Dim intTotal As Integer
Dim intStockCount As Integer
Dim intCount As Integer
intStockCount = CInt(StockCountTextBox.Text)
intCount = CInt(txtCount.Text)
intTotal = intStockCount + intCount
Me.ProductInfoTableAdapter.updateStock(intTotal, ProductIDTextBox.Text)
StockCountTextBox.Text = Me.ProductInfoTableAdapter.getStock(ProductIDTextBox.Text)
End Sub
Public Class Form1
Protected bs1 As New BindingSource
Protected bs2 As New BindingSource
Protected gv As New DataGridView() With {.Name = "FakeGridView",
.AutoGenerateColumns = False,
.AllowUserToAddRows = True
}
Protected ds As New DataSet("FakeDataSet")
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
AddHandler gv.DataError, AddressOf DataError '***** Fake Event.
Call MakeFakeTable()
Dim Column1 As New DataGridViewTextBoxColumn With {.Name = "พนักงานขาย"}
Dim Column2 As New DataGridViewComboBoxColumn With {.Name = "เขตการขาย"}
Column2.DataSource = bs2
Column2.DataPropertyName = "RegionID"
Column2.DisplayMember = "Name"
Column2.ValueMember = "RegionID"
Me.gv.Columns.Clear()
Me.gv.Columns.AddRange(Column1, Column2)
gv.Columns(0).DataPropertyName = "SaleName"
gv.Columns(1).DataPropertyName = "RegionID"
Me.gv.DataSource = bs1
Me.gv.Location = New Point(10, 10)
Me.gv.Height = 200
Me.Controls.Add(gv)
Me.bs1.Position = 1
End Sub
Private Sub MakeFakeTable()
Dim dtParent As New DataTable("Territory")
Dim dtChild As New DataTable("SaleGirl")
dtChild.Columns.Add("SaleName", GetType(String))
dtChild.Columns.Add("RegionID", GetType(String))
dtChild.Rows.Add(New Object() {"อวบอูม1", "00"})
dtChild.Rows.Add(New Object() {"อวบอูม2", "02"})
dtChild.Rows.Add(New Object() {"อวบอูม3", "03"})
dtChild.Rows.Add(New Object() {"อวบอูม4", "05"})
Me.bs1.DataSource = dtChild
dtParent.Columns.Add("Name", GetType(String))
dtParent.Columns.Add("RegionID", GetType(String))
dtParent.Rows.Add(New Object() {"เหนือ", "01"})
dtParent.Rows.Add(New Object() {"ใต้", "02"})
dtParent.Rows.Add(New Object() {"ตก", "04"})
dtParent.Rows.Add(New Object() {"ออก", "05"})
Me.bs2.DataSource = dtParent
ds.Tables.AddRange({dtParent, dtChild})
'Create DataRelation and Drop constraints.
Dim rt As New DataRelation("R1", ds.Tables("Territory").Columns("RegionID"), ds.Tables("SaleGirl").Columns("RegionID"), False)
ds.Relations.Add(rt)
End Sub
'FAKE Event.
Private Sub DataError(sender As Object, e As System.Windows.Forms.DataGridViewDataErrorEventArgs)
'If e.Exception.Message = "DataGridViewComboBoxCell value is not valid." Then
' e.ThrowException = False
'End If
End Sub
End Class