check combobox selected index changed in datagridview in vb.net

Viewed 27

Hi all I'm developing an accounting software for a small business where I'm facing an issue in invoice part where user is going to put item for buy / create invoice here I'm fetching data from items table to display as a combobox in data grid view but I want to fetch amount and item code when user will select a item in combo box also I want to hide the selected item from the next row so user is not able to select same item again and again. I had tried all possible solution available on internet mostly are for normal combobox or else in the c# which i'm not able to understand.

Image of invoice page

1 Answers

You can do it under the CellEndEdit Event

Private Sub dgv_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv.CellEndEdit

        Dim StockCol As Integer = dgv.Columns("StockColName").Index  ' Get the combobox column index



        Try

             For i = 0 To dgv.RowCount - 1

            If e.RowIndex <> i Then     'skip the comparison for current row
                If dgv.Item(StockCol , i).Value = dgvPurchase.Item(StockCol , e.RowIndex).Value Then
                    MsgBox("Similar Item is selected", MsgBoxStyle.Critical, "Error")
                    dgv.Item(StockCol , e.RowIndex).Value = ""  'reset the cell to ""
                    Exit Sub
                End If

            End If
        Next
        Catch
        End Try
Related