大家下午好,我现在遇到的问题是我无法将值选为组合框,我正在尝试为数据网格中每个单元格的组合框中的每个项目设置文本和值。我的代码:
类我的列表项:
Public Class MyListItem
Private mText As String
Private mValue As String
Public Sub New(ByVal pText As String, ByVal pValue As String)
mText = pText
mValue = pValue
End Sub
Public ReadOnly Property Text() As String
Get
Return mText
End Get
End Property
Public ReadOnly Property Value() As String
Get
Return mValue
End Get
End Property
Public Overrides Function ToString() As String
Return mText
End Function
End Class
表单加载:
DataGridView1.Rows.Add()
Dim dgvcbc As DataGridViewComboBoxCell = DirectCast(DataGridView1.Rows(0).Cells(0), DataGridViewComboBoxCell)
dgvcbc.Items.Add(New MyListItem("Text to be displayed", "value of the item"))
尝试显示选定的值:
Dim oItem As MyListItem = CType(**dgvcbc.SelectedItem**, MyListItem)
MessageBox.Show("The Value of the Item selected is: " & oItem.Value)
错误: “SelectedItem”不是“System.Windows.Forms.DataGridViewComboBoxCell”的成员
如果有人知道如何使用组合框为每个单元格的每个项目设置值和文本,我将不胜感激谢谢