繁体   English   中英

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

[英]Programmatically Changing a DataGridViewComboBox Display Member

这是一个vb.net winforms应用程序。 我在datagridview中有一个绑定的DataGridViewCombo框列。 这允许用户选择6种不同的交易类型。 现金交易和支票交易都具有相同的ValueMember。 如果Check Number列有值或Not值,那么决定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循环,通过使用每个您可以在循环中访问整行。

通过将单元格ctyping到DataGridViewComboBoxCell,您可以访问显示成员和值成员。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM