I have DataGridView which contains two ComboBox columns. The second ComboBox will be filled with data depending on the selected value from first ComboBox in datagridview.
problem is that when i select first row it work porperly .. but in second row second column it does't work properly .. it will showing some value as it show in first row second column.
Dim comm As New Common
Private EditRow As Integer = -1
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
EditRow = DataGridView1.CurrentRow.Index
If DataGridView1.CurrentCellAddress.X = 0 Then
Me.column0ComboBox = DirectCast(e.Control, ComboBox)
End If
End Sub
Private Sub DataGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
Me.column0ComboBox = Nothing
End Sub
Private Sub GridMode_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dstemp As New DataSet
sqry = "sp_dtgLoad_tbitemmaster"
SqlCom = New SqlCommand(sqry, mycon)
SqlCom.CommandType = CommandType.StoredProcedure
SqlCom.Parameters.Add("@code ", SqlDbType.BigInt).Value = 1
SqlCom.Parameters.Add("@itemid", SqlDbType.BigInt).Value = 0
AdpComm = New SqlDataAdapter(SqlCom)
AdpComm.Fill(dstemp, "tbItemMasterHeader")
DataGridView1.DataSource = dstemp.Tables("tbBranchMaster")
Try
Dim dstemp12 As New DataSet
sqry = "sp_dtgLoad_tbitemmaster"
SqlCom = New SqlCommand(sqry, mycon)
SqlCom.CommandType = CommandType.StoredProcedure
SqlCom.Parameters.Add("@code ", SqlDbType.BigInt).Value = 1
SqlCom.Parameters.Add("@itemid", SqlDbType.BigInt).Value = 0
AdpComm = New SqlDataAdapter(SqlCom)
AdpComm.Fill(dstemp12, "tbBankMaster")
Column1.ValueMember = "itemId"
Column1.DisplayMember = "Itemname"
Column1.DataSource = dstemp12.Tables(0)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private WithEvents column0ComboBox As ComboBox
Private Sub column_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles column0ComboBox.SelectedIndexChanged
Dim dstemp As New DataSet
sqry = "sp_binditemsize"
SqlCom = New SqlCommand(sqry, mycon)
SqlCom.CommandType = CommandType.StoredProcedure
SqlCom.Parameters.Add("@code ", SqlDbType.BigInt).Value = 1
SqlCom.Parameters.Add("@itemid", SqlDbType.BigInt).Value = column0ComboBox.SelectedValue
AdpComm = New SqlDataAdapter(SqlCom)
AdpComm.Fill(dstemp, "tbItemMasterHeader")
DataGridView1.DataSource = dstemp.Tables("tbBranchMaster")
Try
Dim dstemp12 As New DataSet
sqry = "sp_binditemsize"
SqlCom = New SqlCommand(sqry, mycon)
SqlCom.CommandType = CommandType.StoredProcedure
SqlCom.Parameters.Add("@code ", SqlDbType.BigInt).Value = 1
SqlCom.Parameters.Add("@itemid", SqlDbType.BigInt).Value = column0ComboBox.SelectedValue
AdpComm = New SqlDataAdapter(SqlCom)
AdpComm.Fill(dstemp12, "tbBankMaster")
Column2.ValueMember = "itemsizeid"
Column2.DisplayMember = "SizeName"
Column2.DataSource = dstemp12.Tables(0)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub DataGridView1_DataError(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError
If (e.Context = (DataGridViewDataErrorContexts.Formatting Or DataGridViewDataErrorContexts.PreferredSize)) Then
e.ThrowException = False
End If
End Sub