2016-05-04 153 views
0

VB.net 我有一个datagridview设置与一列绑定到另一个数据库作为comboboxSystem.ArgumentException:DatagridViewComboBoxCell值无效

我有

System.ArgumentException:值的DataGridViewComboBoxCell无效

错误不断,当我第一次开始,因为在那是不是在combobox DB信息。我删除了这些条目,错误似乎消失了。当我通过我的项目工作时,我仍然时常得到它。此外,出现错误,我关闭了盒子,DGV正确填充,一切正常。

我有一个“填充”按钮,同时填充datagridviewcombobox。我试图在datagrid adapterfill之后延迟comboboxadapterfill声明,并且它似乎没有效果。

看起来好像它只是随机出现在填充第一次点击。如果第一项填充工作,我可以再次点击或更改过滤器,一切都很好。

还有一件事。当事物填充时,当单元格/行中存在数据时,似乎会发生这种情况。如果我从行中删除所有数据,则不会出错。如果我做一些组合框选择并保存,然后重新填充。我可以得到错误。

希望我的描述很有意义。

我已经在过滤器中包含了填充事件的代码。谢谢。

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

而是任意延迟combobox adapterfill语句,尽量填充ComboBoxDataBindingComplete事件触发时的DataGridView

+0

伟大的建议!我现在明白为什么会发生这种情况。我已经更改了代码,并且无法再重新创建活动。感谢您的帮助! – sds5150

+0

@ sds5150完全没问题!我很高兴它解决了!快乐的编码! – ic3man7019