Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winforms 未绑定DataGridView WinForm控件中的DataGridViewComboxCell_Winforms_Datagridview_Drop Down Menu - Fatal编程技术网

Winforms 未绑定DataGridView WinForm控件中的DataGridViewComboxCell

Winforms 未绑定DataGridView WinForm控件中的DataGridViewComboxCell,winforms,datagridview,drop-down-menu,Winforms,Datagridview,Drop Down Menu,我不熟悉DataGridView WinForm控件,只是不喜欢数据绑定。100年前我曾使用Spread OCX,发现它很友好。现在我遇到了一个问题,尝试做一些简单的事情: 我有一个有两列的网格: 1名 2地位 我想循环浏览我收集的中国签证,并显示申请人的姓名和申请状态。我想让status列成为一个下拉列表,允许用户通过在下拉列表中选择不同的项来更改值 这就是我正在做的。我有一种感觉,这不是大多数人编写代码时所采用的数据绑定方式,但你可以这样做: Private Sub PopulateGrid

我不熟悉DataGridView WinForm控件,只是不喜欢数据绑定。100年前我曾使用Spread OCX,发现它很友好。现在我遇到了一个问题,尝试做一些简单的事情:

我有一个有两列的网格: 1名 2地位

我想循环浏览我收集的中国签证,并显示申请人的姓名和申请状态。我想让status列成为一个下拉列表,允许用户通过在下拉列表中选择不同的项来更改值

这就是我正在做的。我有一种感觉,这不是大多数人编写代码时所采用的数据绑定方式,但你可以这样做:

Private Sub PopulateGridVisa()

    grdVisa.Rows.Add(_Order.ChinaVisas.Count)

    For r As Integer = 0 To _Order.ChinaVisas.Count - 1

        Dim CurrentChinaVisa As ChinaVisa = _Order.ChinaVisas(r)

        For c As Integer = 0 To grdVisa.Columns.Count - 1

            Select Case c

                Case 0
                    Dim CurrentCell As DataGridViewCell = grdVisa.Rows(r).Cells(c)
                    CurrentCell.Value = CurrentChinaVisa.SortName

                Case 1

                    Dim CurrentCell As DataGridViewComboBoxCell = CType(grdVisa.Rows(r).Cells(c), DataGridViewComboBoxCell)

                    For Each StatusCode As StatusCode In _frmMain.ApplicationStartup.StatusCodes
                        If StatusCode.StatusCodeId >= StatusCodeEnum.WaitingToReceive Then
                            CurrentCell.Items.Add(StatusCode)
                        End If
                        If StatusCode.StatusCodeId = CurrentChinaVisa.StatusCodeId Then
                            CurrentCell.Value = StatusCode
                        End If
                    Next


            End Select

        Next

    Next

End Sub
这似乎可行,但当用户从下拉列表中选择新的状态值时,将返回以下错误:

---------------------------
DataGridView Default Error Dialog
---------------------------
The following exception occurred in the DataGridView:



System.ArgumentException: DataGridViewComboBoxCell value is not valid.



To replace this default dialog please handle the DataError event.
---------------------------
OK   
---------------------------
为什么?

输入代码,但不要将StatusCode对象添加到Items集合,如下所示:

 CurrentCell.Items.Add(StatusCode)
添加一个字符串,看看它是否有效

CurrentCell.Items.AddStatusCode.ToString