 |
|
combobox in datagridview พอ insert ValueMember เป็นชือ column ที่เราอ้างอิง |
|
 |
|
|
 |
 |
|
ใน datagridview ผมสร้าง combobox ขึ้นมาโดย m
ผลลัพท์แสดงออกมาถูกต้อง แต่พอผมจะ insert to database
Code (VB.NET)
myDataGridViewComboBox.DataSource = Data
myDataGridViewComboBox.ValueMember = "product_id"
myDataGridViewComboBox.DisplayMember = "product_name"
DataGridView1.ColumnCount = 7
DataGridView1.Columns(0).Name = "ชื่อลูกค้า"
DataGridView1.Columns(1).Name = "โรงพยาบาล"
DataGridView1.Columns(2).Name = "ที่อยู่"
DataGridView1.Columns(3).Name = "โรงพยาบาล"
DataGridView1.Columns(4).Name = "ที่อยู่"
DataGridView1.Columns(5).Name = "Tele"
DataGridView1.Columns(6).Name = "Fax"
DataGridView1.Columns.Add(myDataGridViewComboBox)
Private Sub DoInsertData()
Dim i As Integer = 0
For x As Integer = 0 To DataGridView1.RowCount - 2
Me.GenCustomerID()
mCustomer_name = Me.DataGridView1.Item(0, x).Value.ToString()
mCustomer_hospital = Me.DataGridView1.Item(1, x).Value.ToString()
mCustomer_address = Me.DataGridView1.Item(2, x).Value.ToString()
mCustomer_tel = Me.DataGridView1.Item(3, x).Value.ToString()
mCustomer_fax = Me.DataGridView1.Item(4, x).Value.ToString()
mCustomer_email = Me.DataGridView1.Item(5, x).Value.ToString()
mProduct_id = myDataGridViewComboBox.ValueMember
CustomerClass.val_customer_id = InserCustomerID
CustomerClass.val_customer_name = mCustomer_name
CustomerClass.val_customer_hospital = mCustomer_hospital
CustomerClass.val_customer_address = mCustomer_address
CustomerClass.val_customer_tel = mCustomer_tel
CustomerClass.val_customer_fax = mCustomer_fax
CustomerClass.val_customer_email = mCustomer_email
CustomerClass.val_product_id = myDataGridViewComboBox.ValueMember '<----- ค่าเป็น "product_id" ไม่ใช่ data in table
i = CustomerClass.InsertData(CustomerClass)
Next
MsgBox("หมดแล้วจ๊ะ")
End Sub
ช่วยแนะนำด้วยครับ ขอบคุณครับ
ค่ากลับเป็น
Tag : .NET, Ms SQL Server 2008, Win (Windows App), VB.NET, VS 2010 (.NET 4.x)
|
ประวัติการแก้ไข 2012-07-23 16:39:12
|
 |
 |
 |
 |
Date :
2012-07-23 16:38:13 |
By :
AoFzaIT |
View :
1866 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง combobox.text ดู
|
 |
 |
 |
 |
Date :
2012-07-24 09:39:51 |
By :
อิอิ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับ โดยอาศัย event ของ Datagridview = EditingControlShowing
Code (VB.NET)
Private Sub DataGridView1_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
Dim Combobox As ComboBox = CType(e.Control, ComboBox)
If (Combobox IsNot Nothing) Then
'Remove an existing event-handler
RemoveHandler Combobox.SelectedIndexChanged, New EventHandler(AddressOf DataGridView1_SelectionChanged)
'Add the event handler.
AddHandler Combobox.SelectedIndexChanged, New EventHandler(AddressOf DataGridView1_SelectionChanged)
End If
End Sub
Private Sub DataGridView1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim comboBox As ComboBox = CType(sender, ComboBox)
'Display selected value
MsgBox("ProgramID: " & comboBox.SelectedValue.ToString)
End Sub
แบ่งปันความรู้คนที่ไม่ทราบแล้วค้นหาเผื่อมาเจอครับ ^-^
|
ประวัติการแก้ไข 2012-07-24 10:16:48
 |
 |
 |
 |
Date :
2012-07-24 10:15:46 |
By :
AoFzaIT |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
 
|
 |
 |
 |
 |
Date :
2012-07-27 14:58:39 |
By :
KT-Revenue |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|