vb Code:
Public Class Form1
Dim loading As Boolean = True
Dim values() As Integer = {0, 695, 545, 545, 545, 480, 480, 480, 480, 395, 395, 395, 395, 395, 395, 395, 395}
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dgvComboboxes As DataGridViewComboBoxColumn = DirectCast(DataGridView1.Columns(1), DataGridViewComboBoxColumn)
dgvComboboxes.DataSource = New String() {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"}
loading = False
End Sub
Private Sub DGVComboIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim cb As ComboBox = DirectCast(sender, ComboBox)
DataGridView1(3, DataGridView1.CurrentCell.RowIndex).Value = If(CBool(DataGridView1(2, DataGridView1.CurrentCell.RowIndex).Value) = True, ((CInt(cb.SelectedItem) * values(CInt(cb.SelectedItem))) * 0.85).ToString("c2"), (CInt(cb.SelectedItem) * values(CInt(cb.SelectedItem))).ToString("c2"))
End Sub
Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
If Not loading Then
If e.ColumnIndex = 2 Then
DataGridView1(3, e.RowIndex).Value = If(CBool(DataGridView1(2, e.RowIndex).Value) = True, ((CInt(DataGridView1(1, e.RowIndex).Value) * values(CInt(DataGridView1(1, e.RowIndex).Value))) * 0.85).ToString("c2"), (CInt(DataGridView1(1, e.RowIndex).Value) * values(CInt(DataGridView1(1, e.RowIndex).Value))).ToString("c2"))
End If
End If
End Sub
Private Sub DataGridView1_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged
If DataGridView1.CurrentCell.ColumnIndex = 2 Then
DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)
End If
End Sub
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
' Attempt to cast the EditingControl to a ComboBox.
Dim cb As ComboBox = TryCast(e.Control, ComboBox)
If cb IsNot Nothing Then
RemoveHandler cb.SelectedIndexChanged, AddressOf DGVComboIndexChanged
AddHandler cb.SelectedIndexChanged, AddressOf DGVComboIndexChanged
End If
End Sub
End Class