【问题标题】:Why can't I assign this DataGridViewComboBoxCell to the cell I want?为什么我不能将此 DataGridViewComboBoxCell 分配给我想要的单元格?
【发布时间】:2015-03-28 00:10:38
【问题描述】:

我的 DataGridViewComboBoxCell 对象出现了一系列奇怪的问题。仅供参考,我使用的是单元格而不是列,因为我的数据是按行而不是按列组织的。

我的第一个问题是我似乎无法正确分配给我的 DataGridView。当我在我的代码中做一个直接的分配时很好:

Dim MyDropDown As New DataGridViewComboBoxCell()
'Code here to populate dropdown
MyForm.DataGridView1(col, row) = MyDropDown

当我尝试使用一个过程来做同样的事情时遇到了麻烦:

Dim MyDropDown As New DataGridViewComboBoxCell()
'Code here to populate dropdown
SetUpDataViewGridDropdown(MyDropDown, MyForm.DataGridView1(col, row))

。 . .

Public Sub SetUpDataViewGridDropdown(ByRef dd As DataGridViewComboBoxCell, _
                                 ByRef ddTarget As DataGridViewCell)

ddTarget = dd
'Do some more interesting stuff here
End Sub

我没有收到错误,但 DataGridView 呈现时不显示下拉菜单。所以任务似乎没有发生。我错过了什么?

【问题讨论】:

    标签: vb.net datagridview datagridviewcomboboxcell


    【解决方案1】:

    你做错了。

    MyForm.DataGridView1(col, row) 获取当前位于DataGridView 中的单元格。所以你在你的函数中所做的只是改变ddTarget变量的引用对象,这是没有用的。

    试试这样的:

    Public Sub SetUpDataViewGridDropdown(ByRef dd As DataGridViewComboBoxCell, _
                                 ByVal rowIndex As Int, _
                                 ByVal columnIndex As Int)
    
    MyForm.DataGridView1(columnIndex, rowIndex) = dd 
    'Do some more interesting stuff here
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-20
      • 2012-11-10
      • 1970-01-01
      • 2023-02-21
      • 2016-12-22
      • 1970-01-01
      相关资源
      最近更新 更多