Click here to Skip to main content
15,891,859 members
Please Sign up or sign in to vote.
2.20/5 (3 votes)
See more:
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.

VB
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

            'Handle the event(s) of the control while we are editing.        
            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
        '            SendKeys.Send("{TAB}")
        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"
            'DataGridView1.Rows.Add(1)
            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)
            'DataGridView1.Rows(EditRow).Cells(1).Value = dstemp12.Tables(0).Columns(3)


        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
Posted
Updated 1-Aug-13 6:25am
v2
Comments
Mandy Nagra 30-Jul-13 5:28am    
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
Member 12987001 9-Oct-17 15:38pm    
Did you find solution same problem here
Thanks7872 30-Jul-13 5:40am    
Post the code.
Mandy Nagra 30-Jul-13 5:44am    
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

'Handle the event(s) of the control while we are editing.
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
' SendKeys.Send("{TAB}")
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"
'DataGridView1.Rows.Add(1)
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)
'DataGridView1.Rows(EditRow).Cells(1).Value = dstemp12.Tables(0).Columns(3)


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
Kschuler 1-Aug-13 12:27pm    
It's a lot easier for us to help when we can see the code formatted. Next time, instead of posting extra information in the comments, please click the Improve Question link and post your code in the original question. I think you'll get more help that way.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900