在 GridView_RowCellClick 上向 DevXpress 网格动态添加组合框

Add a combo box to a DevXpress grid dynamically on GridView_RowCellClick

我正在使用 "DevXpress.XtraGrid.GridView" 并编写了以下代码以在单元格上显示组合框。当用户单击单元格时会发生这种情况。在 Debug 或 运行 模式下,代码可以正确执行但什么也没有发生。我在代码中做错了吗?请指教。

这是我的代码:

    Private Sub GridView1_RowCellClick(sender As Object, e As RowCellClickEventArgs) Handles GridView1.RowCellClick
        Try
            Dim myNewLawyersCol As GridColumn = GridView1.Columns("NewLawyers")
            If (e.Column.Equals(myNewLawyersCol)) Then
                Dim riCombo As RepositoryItemComboBox = New RepositoryItemComboBox()
                riCombo.Items.Clear()
                riCombo.Items.AddRange(myList)

                GridControl1.RepositoryItems.Add(riCombo)
                GridView1.Columns("NewLawyers").ColumnEdit = riCombo
                GridControl1.Refresh()
            End If
        Catch ex As Exception
            DebugMessage(1, "Error in GridView1_RowCellClick :- " + ex.Message)
        Finally
            Cursor.Current = Cursors.Default
        End Try
    End Sub

谢谢。

Gosha(来自 DevExpress 支持)帮助我解决了问题。

这是他的解释:

"When a user clicks a cell, an editor to edit that cell is created. As far as I understand, you need to change an editor for a particular cell to ComboBoxEdit. If so, the RowCellClick event is not a correct place to do this. To change the editor that will be used for editing a cell, use the GridView.CustomRowCellEditForEditing event. It's specially dedicated for this purpose."

这是我的代码:

    Private Sub GridView1_CustomRowCellEditForEditing(sender As Object, e As CustomRowCellEditEventArgs) Handles GridView1.CustomRowCellEditForEditing
        If (e.Column.FieldName = "NewLawyers") Then
            riCombo.Items.Clear()
            riCombo.Items.AddRange(allLawyersNames)
            e.RepositoryItem = riCombo
        End If
    End Sub