我有一个带有 DataGridViewComboBoxColumn 和 DataGridViewTextBoxColumn 的简单数据网格视图。组合框填充如下:(其中 PNcombo.text 是标准组合框)
Dim objConn As New SqlConnection(DatabaseConnection.FISSQLConnectionString)
Dim str1 As New StringBuilder
str1.Append("SELECT cp.Description, cp.CollectionPointId ")
str1.Append("FROM CollectionPoints cp INNER JOIN ")
str1.Append(" Products p ON cp.ProductIdValue = p.ProductId ")
str1.Append("WHERE p.PartNumber = N'" & Trim(PNcombo.Text) & "'")
Dim objCommand As SqlCommand = New SqlCommand(str1.ToString, objConn)
objConn.Open()
Dim dt As New DataTable
dt.Load(objCommand.ExecuteReader)
Dim colDesription As New DataGridViewComboBoxColumn
With colDesription
.DataSource = dt
.DisplayMember = "Description"
.ValueMember = "Description"
End With
Me.DataGridView1.Columns.Add(colDesription)
Dim colCollectionPoint As New DataGridViewTextBoxColumn
With colCollectionPoint
.Name = "CollectioPntId"
.DataPropertyName = "CollectionPointId"
End With
DataGridView1.Columns.Add(colCollectionPoint)
dgv 中的组合框填充正确,但我需要获取关联的“CollectionPointID”并将其放入 dgv 内的文本框中。
从这里我不知道如何获取我从组合框中选择的单元格值。