这就是我的处境。我有一个DataGridView,它有两列,我正试图将其设置为DataGridViewComboBoxColumns,分别称为“Received”和“Backordered”。
这些组合框的要点是创建一个下拉菜单,以选择当我的公司收到一批货物时收到/延期订购的项目数。这个程序主要在触摸屏上运行,没有鼠标或键盘,这就是为什么我选择使用组合框,而不是仅仅要求一般的用户输入。
我尝试按如下方式设置DataGridView:
'Setup of Combo Box Columns
'shipmentData is the name of the DataGridView
Dim receiveCol As New DataGridViewComboBoxColumn()
receiveCol.HeaderText = "Received"
receiveCol.Name = "Received"
shipmentData.Columns.Add(receiveCol)
Dim backorderCol As New DataGridViewComboBoxColumn()
backorderCol.HeaderText = "Backordered"
backorderCol.Name = "Backordered"
shipmentData.Columns.Add(backorderCol)
上面的代码在
New()
创建窗体时的Sub。我尝试将数据加载到组合框中,如下所示:
Dim rowNum As Integer = 0
For Each op As OrderPart In OrderData.GetPartList()
If op.AmountOrdered > 0 Then
shipmentData.Rows.Add()
shipmentData.Rows(rowNum).Cells("PartNumber").Value = op.PartNumber
shipmentData.Rows(rowNum).Cells("Description").Value = op.Description
shipmentData.Rows(rowNUm).Cells("Ordered").Value = op.AmountOrdered
For it As Integer = 0 To op.AmountOrdered
CType(shipmentData.Rows(rowNum).Cells("Received"), DataGridViewComboBoxCell).Items.Add(it)
CType(shipmentData.Rows(rowNum).Cells("Backordered"), DataGridViewComboBoxCell).Items.Add(it)
Next
rowNum = rowNum + 1
End If
Next
现在,当我运行代码时,将创建组合框,并添加它们的数据。但是,每当我从组合框列表中选择一个数据值,然后尝试移动到另一个sell时,我会得到以下错误:
System.ArgumentException:DataGridViewComboBoxCell值无效。
为什么我会得到这个错误,如何修复它?我似乎不知道我在代码中做错了什么。