sds5150 sds5150 - 6 months ago 103
Vb.net Question

System.ArgumentException:DatagridViewComboBoxCell value not valid

VB.net
I have a

datagridview
set up with one column bound to another database as a
combobox
.

I had the


System.ArgumentException:DatagridViewComboBoxCell value not valid


error constantly when I first started because there was information in the DB that was not in the
combobox
. I deleted these entries and the errored seemed to go away. As I work through my project, I still get it from time to time. In addition, the error occurs, I close the box and the DGV populates correctly and all is well.

I have a "populate" button that populates the
datagridview
and the
combobox
at the same time. I have tried delaying the
combobox
adapterfill
statement after the datagrid
adapterfill
and it doesn't seem to have an effect.

It seems as if it only randomly occurs on the populate first click. If the first populate works, I can click again or change a filter and all is well.

One more thing. It seems to happen when there is data in the cell/row when things are populated. If I remove all data from the rows, no error. If I make some combobox selections and save, then repopulate. I can get the error.

Hope my description makes sense.

I have included the code for the populate event with the filters. Thanks.

Private Sub xP3PopulateBtn_Click(sender As Object, e As EventArgs) Handles xP3PopulateBtn.Click

Delay(1)
'Active Filters
Try
Dim strFilterP3 As String = String.Empty
'CheckBox Filtering code=Search for Incomplete Cells Line 2 Only
If xP3IncompleteCellsChkBox.Checked = True And
xP3FirstShiftChkBox.Checked = False And
xP3SecondShiftChkBox.Checked = False Then
strFilterP3 = ("(DTReasonBadgeNo Is Null Or DTEventReason Is Null Or DTReasonDateTime Is Null)")
strFilterP3 = strFilterP3 & String.Format(" And [LineID]= '3'")
ProductionDownTimeTableBindingSource.Filter = strFilterP3
ProductionDownTimeTableBindingSource.Sort = "ProductionUpDateTime desc"
End If

'CheckBox Filtering code=Search for Incomplete Cells on first and second shift only Lines 1N and 1S Only
If xP3IncompleteCellsChkBox.Checked = True And
xP3FirstShiftChkBox.Checked = True And
xP3SecondShiftChkBox.Checked = True Then
strFilterP3 = ("(DTReasonBadgeNo Is Null Or DTEventReason Is Null Or DTReasonDateTime Is Null) And (Shift = 1 Or Shift = 2)")
strFilterP3 = strFilterP3 & String.Format(" And [LineID]= '3'")
ProductionDownTimeTableBindingSource.Filter = strFilterP3
ProductionDownTimeTableBindingSource.Sort = "ProductionUpDateTime desc"
End If

'CheckBox Filtering code=Search for Incomplete Cells on first shift only Line 2 Only
If xP3IncompleteCellsChkBox.Checked = True And
xP3FirstShiftChkBox.Checked = True And
xP3SecondShiftChkBox.Checked = False Then
strFilterP3 = ("(DTReasonBadgeNo Is Null Or DTEventReason Is Null Or DTReasonDateTime Is Null) and Shift = 1")
strFilterP3 = strFilterP3 & String.Format(" and [LineID]= '3'")
ProductionDownTimeTableBindingSource.Filter = strFilterP3
ProductionDownTimeTableBindingSource.Sort = "ProductionUpDateTime desc"
End If

'CheckBox Filtering code=Search for Incomplete Cells on second shift only Line 2 Only
If xP3IncompleteCellsChkBox.Checked = True And
xP3FirstShiftChkBox.Checked = False And
xP3SecondShiftChkBox.Checked = True Then
strFilterP3 = ("(DTReasonBadgeNo Is Null Or DTEventReason Is Null Or DTReasonDateTime Is Null) and Shift = 2")
strFilterP3 = strFilterP3 & String.Format(" and [LineID]= '3'")
ProductionDownTimeTableBindingSource.Filter = strFilterP3
ProductionDownTimeTableBindingSource.Sort = "ProductionUpDateTime desc"
End If

'CheckBox Filtering Code=Incomplete and Complete Cells on First Shift Only Line 2 Only
If xP3IncompleteCellsChkBox.Checked = False And
xP3FirstShiftChkBox.Checked = True And
xP3SecondShiftChkBox.Checked = False Then
strFilterP3 = "Shift = 1"
strFilterP3 = strFilterP3 & String.Format(" and [LineID]= '3'")
ProductionDownTimeTableBindingSource.Filter = strFilterP3
ProductionDownTimeTableBindingSource.Sort = "ProductionUpDateTime desc"

End If

'CheckBox Filtering Code=Incomplete And Complete Cells on Second Shift Only Line 2 Only
If xP3IncompleteCellsChkBox.Checked = False And
xP3FirstShiftChkBox.Checked = False And
xP3SecondShiftChkBox.Checked = True Then
strFilterP3 = "Shift = 2"
strFilterP3 = strFilterP3 & String.Format(" and [LineID]= '3'")
ProductionDownTimeTableBindingSource.Filter = strFilterP3
ProductionDownTimeTableBindingSource.Sort = "ProductionUpDateTime desc"
End If


'CheckBox Filtering Code=S how All Line 2 Only
If xP3IncompleteCellsChkBox.Checked = False And
xP3FirstShiftChkBox.Checked = False And
xP3SecondShiftChkBox.Checked = False Then
strFilterP3 = "1 = 1"
strFilterP3 = strFilterP3 & String.Format(" and [LineID]= '3'")
ProductionDownTimeTableBindingSource.Filter = strFilterP3
ProductionDownTimeTableBindingSource.Sort = "ProductionUpDateTime desc"

End If

'CheckBox Filter Code Show all Data from First and Second Shift Line 2 Only
If xP3IncompleteCellsChkBox.Checked = False And
xP3FirstShiftChkBox.Checked = True And
xP3SecondShiftChkBox.Checked = True Then
strFilterP3 = ("(Shift = 1 Or Shift = 2)")
strFilterP3 = strFilterP3 & String.Format(" And [LineID]= '3'")
ProductionDownTimeTableBindingSource.Filter = strFilterP3
ProductionDownTimeTableBindingSource.Sort = "ProductionUpDateTime desc"
End If

'This line of code loads data into the 'ProductionDownTimeDataSet.ProductionDownTimeTable' table.

Me.ProductionDownTimeTableTableAdapter.Fill(Me.ProductionDownTimeDataSet1.ProductionDownTimeTable)

'After Binding the DataSource to the ComboBox in the DatGrid, this populates the data
Me.DTCodeDataTableAdapter.Fill(Me.DownTimeCodesDataSet.DTCodeData)

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

End Sub

Answer

Instead of arbitrarily delaying the combobox adapterfill statement, try filling the ComboBox when the DataBindingComplete event fires for the DataGridView.

Comments