如何读取这个datagridview中combobox的选定值
我将一个checkedlistbox中选中的值添加到另一个datagridview的combobox中。现要读取这个datagridview中combobox的选定值,红字部分该怎么写?
因为combobox是用代码插进去的,所以我用DataGridView3.Rows(j).Cells(x).Value读取失败,找不到是第几列。
虽然我设的column.DisplayIndex = 2,但实际读取时不是cells(2)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
代码如下:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim tbl As New DataTable("tbl")
tbl.Columns.Add("Display", GetType(String))
tbl.Columns.Add("Value", GetType(Integer))
For i = 0 To rs - 1
tbl.Rows.Add(CheckedListBox2.CheckedItems.Item(i).ToString, i)
Next
Dim column As New DataGridViewComboBoxColumn()
column.DataPropertyName = "BZFS"
column.DataSource = tbl
column.ValueMember = "Value"
column.DisplayMember = "Display"
column.HeaderText = "包装方式"
column.DisplayIndex = 2
DataGridView3.Columns.Add(column)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim j As Integer = 0
For j = 0 To DataGridView3.Rows.Count - 1
zzz = New String(DataGridView3.Rows(j).Cells(2).Value)
If zzz = String.Empty Then
Else
Dim dcmd As New SqlCommand("insert into 工时成本 (包装单号,员工编号,包装方式,数量) values(@bno,@yno,@fs,@sl)", conn)
dcmd.Parameters.AddWithValue("@bno", nn)
dcmd.Parameters.AddWithValue("@yno", DataGridView3.Rows(j).Cells(0).Value)
dcmd.Parameters.AddWithValue("@fs", ????????) '将combobox的选定值赋值给@fs
dcmd.Parameters.AddWithValue("@sl", DataGridView3.Rows(j).Cells(2).Value)
Try
dcmd.ExecuteNonQuery()
DataGridView3.Rows(j).Cells(2).Value = ""
Catch ex As SqlException
MsgBox("工时成本写入失败")
End Try
zzz = ""
End If
Next
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~