2016-05-04 89 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