我有一個簡單的DataGridView DataGridViewComboBoxColumn和DataGridViewTextBoxColumn。組合框填充如下:(其中PNcombo.text是一個標準的ComboBox)如何獲取DataGridViewComboBoxColumn中的單元格的值
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的COMBOX正確填充,但我需要得到相關的 「CollectionPointID」 和把它放在dgv的文本框中。
從這裏我不知道如何獲得我從組合框中選擇的單元格值。
如果你正在尋找從你的組合框中選擇任何值,這應該做'DataGridView1.SelectedRows(0).Cells(「Description」)。Value' – Alex
@Alex - 這就是我一直在尋找。我結束了與DataGridView1.CurrentRow.Cells(「CollectionPntId」)。價值工作正常。 – ctmcklowe96