为DataGridView添加下拉列
设置单击下拉模式(否则需要点两下才能显示下拉框):
DataGridView属性 EditMode 为 EditOnEnte
v1.Columns.RemoveAt(1)
Dim colShow As New DataGridViewComboBoxColumn
colShow.Name = "mName"
colShow.HeaderText = "姓名"
colShow.Width = 100
For Each kp As DictionaryEntry In ht
colShow.Items.Add(kp.Key)
Next
v1.Columns.Insert(1, colShow)
DataGridViewComboBoxColumn值改变时触发事件
Private Sub v1_CurrentCellDirtyStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles v1.CurrentCellDirtyStateChanged
If v1.IsCurrentCellDirty Then
v1.CommitEdit(DataGridViewDataErrorContexts.Commit)
End If
End Sub
Private Sub v1_CellValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles v1.CellValueChanged
If v1.Rows.Count > 1 Then
ListBox1.Items.Add(v1.Rows(e.RowIndex).Cells(1).Value.ToString())
End If
End Sub