Vb.net 以编程方式更改DataGridViewComboBox显示成员

Vb.net 以编程方式更改DataGridViewComboBox显示成员,vb.net,winforms,datagridview,Vb.net,Winforms,Datagridview,这是一个vb.net winforms应用程序。我在datagridview中有一个绑定的DataGridViewComboBox列。允许用户选择6种不同的交易类型。现金交易和支票交易都具有相同的ValueMember。决定2是否分开的是检查编号列是否有值。。我的问题在这里很容易看出。两者的ValueMember相同,因此可以使用DisplayMember来设置需要checkNumber的值。这纯粹是为了用户体验,而不是为了将其保存为付款的幕后活动。这是我需要的东西,当然它不正确,因为“支票付款

这是一个vb.net winforms应用程序。我在datagridview中有一个绑定的DataGridViewComboBox列。允许用户选择6种不同的交易类型。现金交易和支票交易都具有相同的ValueMember。决定2是否分开的是检查编号列是否有值。。我的问题在这里很容易看出。两者的ValueMember相同,因此可以使用DisplayMember来设置需要checkNumber的值。这纯粹是为了用户体验,而不是为了将其保存为付款的幕后活动。这是我需要的东西,当然它不正确,因为“支票付款”作为需要整数的ValueMember无效

       For i As Integer = 0 To FinancialDataGridView.RowCount - 1
        If Not IsNothing(FinancialDataGridView.Rows(i).Cells(2).Value) Then
            FinancialDataGridView.Rows(i).Cells(5).Value = "Check Payment"
        End If

    Next


但它给出了一个想法,我认为我可以这样做。。有什么想法吗?

看看下面的代码,我希望它能有所帮助:

 For Each row As DataGridViewRow In FinancialDataGridView.Rows
        If Not IsNothing(row.Cells(2).Value) Then
            With CType(row.Cells(5), DataGridViewComboBoxCell)
                ' This gives you the ability to set the value member if you have the ID
                .ValueMember = 1
                ' This gives you the ability to set it by display memeber if you only have the string (Less safe)
                .DisplayMember = ("Your string")
            End With
        End If
    Next
您将看到我已经更改了for循环,通过使用for-each,您可以在循环中访问整行


通过将单元格键入DataGridViewComboxCell,您可以访问display成员和value成员。

我已经尝试了您提出的解决方案,但是。当datagrid显示时,没有任何更改。尽管单元格(2)位置中存在值,但组合框仍显示现金支付事件。。My.DisplayMember属性设置为=(“支票付款”),这是数据库中的有效DisplayMember。。。