目前,当使用 ComboBoxes 在 DataGridViewColumn 中选择一个值时,用户必须单击该单元格才能通过CellValueChanged
DataGridView 上的事件刷新值。
我想要实现的是,一旦在 ComboBox 中选择了一个值,就会触发刷新。
下面是我尝试做的事情,以便在打开/关闭下拉列表时触发刷新,但它仅在单击组合框并且下拉列表可见时执行,而不是在选择值时执行。
Private Sub PL_DGV_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles PL_DGV.EditingControlShowing
Dim cb As ComboBox = TryCast(e.Control, ComboBox)
If cb IsNot Nothing Then
Dim editingComboBox As ComboBox = DirectCast(e.Control, ComboBox)
RemoveHandler editingComboBox.SelectedIndexChanged,
New EventHandler(AddressOf editingComboBox_SelectedIndexChanged)
AddHandler editingComboBox.SelectedIndexChanged,
New EventHandler(AddressOf editingComboBox_SelectedIndexChanged)
End If
End Sub
Private Sub editingComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim dgvc As DataGridViewCell = TryCast(Me.PL_DGV.CurrentCell, DataGridViewCell)
RefreshCarriage(dgvc.RowIndex)
End Sub