我在datagrid中创建了三个组合框,并且每当我立即更改组合框中的值时,我都尝试更改另一个datagrid单元中的单元格值。我该怎么办?
code is here
私人Sub DataGridView1_EditingControlShowing(ByVal发送者为System.Object, ByVal e作为System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) 处理DataGridView1.EditingControlShowing
' Only for a DatagridComboBoxColumn at ColumnIndex 6 and 7.
If DataGridView1.CurrentCell.ColumnIndex = 6 AndAlso 7 Then
Dim combo As ComboBox = CType(e.Control, ComboBox)
If (combo IsNot Nothing) Then
' Remove an existing event-handler, if present, to avoid
' adding multiple handlers when the editing control is reused.
RemoveHandler combo.SelectionChangeCommitted, New EventHandler(AddressOf ComboBox_SelectionChangeCommitted)
' Add the event handler.
AddHandler combo.SelectionChangeCommitted, New EventHandler(AddressOf ComboBox_SelectionChangeCommitted)
End If
End If
End Sub
Private Sub ComboBox_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim combo As ComboBox = CType(sender, ComboBox)
Console.WriteLine("Row: {0}, Value: {1}", DataGridView1.CurrentCell.RowIndex, combo.SelectedItem)
For Each row As DataGridViewRow In DataGridView1.Rows
Dim i As Double
Dim y As Double
i = CDec((row.Cells(5).Value) * (row.Cells(6).Value) * 1 / 100) + CDec(row.Cells(5).Value)
i = Math.Round(i, 2, MidpointRounding.AwayFromZero)
y = CDbl(i * (row.Cells(7).Value))
row.Cells(9).Value = y
Next
End Sub