こんにちは、私が今抱えている問題は、コンボボックスとして選択された値を取得できないことです.データグリッドの各セルのコンボボックスの各項目にテキストと値を設定しようとしています. 私のコード:
クラス MyListItem:
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' のメンバーではありません
コンボボックスを使用して各セルの各項目に値とテキストを設定する方法を誰かが知っていれば、とても感謝しています。