1

これは vb.net winforms アプリケーションです。データグリッドビュー内にバインドされた DataGridViewCombo ボックス列があります。これにより、ユーザーは 6 つの異なるトランザクション タイプを選択できます。現金取引と小切手取引はどちらも同じ ValueMember を持ちます。2つの違いを決定するのは、Check Number列に値があるかどうかです..私の問題はここで簡単にわかります. 両方が同じであるための 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

ボタン列のプロパティ

しかし、それは私がそれを行うことができると私が考えている方法のアイデアを与えてくれます.. 何かアイデアはありますか?

4

1 に答える 1

3

以下のコードを見てください。

 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 each を使用して、ループ内で行全体にアクセスできるようにすることで、for ループを変更したことがわかります。

また、セルを DataGridViewComboBoxCell に ctyping することで、表示メンバーと値メンバーにアクセスできます。

于 2012-10-09T16:41:32.250 に答える