Hello
Mr/Ms.
I have one porblem. I used datagridviewcombocolum. Inserting to database is ok. but when select from database, Error message alert me . Error message is following...
'
'
The following Exception is occured in DataGridView:
System.ArgumentException : DataGridComboboxCell value is not valid.
To replace this default dialog please handle the data error event.
my code is following
Public Sub AddToGridComboNC(ByRef _Combo As DataGridViewComboBoxCell, ByVal spName As String, ByVal displaySTR As String, ByVal ValueSTR As String, Optional ByVal dtname As String = "tmp01", Optional ByVal _cAction As String = "3")
Try
Dim staff_DataSet As New DataSet
Dim staff_DataAdapter As New SqlDataAdapter
m_String = spName & " 0, 0," & _cAction
Try
staff_DataAdapter = New SqlDataAdapter(m_String, m_Connection)
staff_DataAdapter.Fill(staff_DataSet, dtname)
_Combo.DataSource = staff_DataSet.Tables(0)
_Combo.DisplayMember = displaySTR
_Combo.ValueMember = ValueSTR
Catch ex As Exception
MessageBox.Show(ex.Message, MessageTitle)
Err.Clear()
Finally
staff_DataSet.Dispose()
staff_DataAdapter.Dispose()
m_Connection.Close()
End Try
Catch ex As Exception
MessageBox.Show(ex.Message, MessageTitle)
Err.Clear()
End Try
End Sub
I call above method at dgvpurchase_CellEnter()
AddToGridComboNC(dgvpurchase.Item(4, _CurrentRow), "Storeprocedure_name", "displaymember_name", "value_membername", "MeasurementUnit")
Friend Sub RetrieveDataGridView(ByRef _DataGridView As DataGridView, ByVal a As String, ByVal Action As String)
Dim purchase_dataset As New DataSet
Dim purchase_dataadapter As New SqlDataAdapter
Dim cbodatagrid As New DataGridViewComboBoxColumn
m_String = "SP_SELECT_VENDORPURCHASEDATEIL_20110315_NC '" & a & "',0,0,0," & Action
purchase_dataadapter = New SqlDataAdapter(m_String, m_Connection)
purchase_dataadapter.Fill(purchase_dataset, "Item")
_tmpDT = purchase_dataset.Tables(0)
Dim i As Integer
For i = 0 To purchase_dataset.Tables(0).Rows.Count - 1
With purchase_dataset.Tables(0)
_DataGridView.Rows.Add()
_DataGridView.Rows(i).Cells(0).Value = i + 1
_DataGridView.Rows(i).Cells(1).Value = .Rows(i).Item("productCode").ToString
_DataGridView.Rows(i).Cells(2).Value = .Rows(i).Item("Description").ToString
_DataGridView.Rows(i).Cells(3).Value = .Rows(i).Item("weight").ToString
cbodatagrid.DisplayMember = .Rows(i).Item("MUName").ToString
Try
_DataGridView.Item(4, i).Value = cbodatagrid.DisplayMember
Catch ex As Exception
End Try
_DataGridView.Rows(i).Cells(5).Value = .Rows(i).Item("UnitQty").ToString
_DataGridView.Rows(i).Cells(6).Value = FormatNumber(.Rows(i).Item("vendorpurchaseprice"), 2)
_DataGridView.Rows(i).Cells(7).Value = FormatNumber(.Rows(i).Item("Amount"), 2)
_DataGridView.Rows(i).Cells(8).Value = .Rows(i).Item("productID").ToString
End With
Next
End Sub
Please help me as soon as possible ... and please reply to [Email removed to avoid SPAM]
Thanks...