VB.net
我有一个datagridview
设置,其中一列绑定到另一个数据库combobox
。
我有
我第一次启动时出现System.ArgumentException:DatagridViewComboBoxCell值无效
错误,因为数据库中的信息不在combobox
中。我删除了这些条目,错误似乎消失了。当我完成我的项目时,我仍然不时地得到它。此外,发生错误,我关闭框,DGV正确填充,一切都很好。
我有一个"填充"同时填充datagridview
和combobox
的按钮。我尝试在datagrid combobox
之后延迟adapterfill
adapterfill
语句,但它似乎没有效果。
好像它只是在填充的第一次点击中随机出现。如果第一个填充工作,我可以再次点击或更改过滤器,一切都很好。
还有一件事。当填充内容时,单元格/行中有数据时似乎会发生这种情况。如果我从行中删除所有数据,没有错误。如果我做了一些组合框选择并保存,那么重新填充。我可以得到错误。
希望我的描述有意义。
我已经使用过滤器包含了populate事件的代码。谢谢。
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
答案 0 :(得分:0)
不要随意推迟combobox adapterfill
语句,请在ComboBox
事件触发DataBindingComplete
时填写DataGridView
。