2 つの DataGridViewComboBoxColumns を持つ DataGridView があります。最初の列で選択した項目を使用して、2 番目の列の項目の再入力を行ごとにトリガーしたいと考えています。
ここに私がこれまで持っているコードがあります。「addlInfoParentCat」は最初の列を識別し、currentRow.Cells.Item(1) は再入力する DataGridViewComboBoxCell です。ExtEventAdditionalInfoType は、文字列と値のペアを含む、私が定義した型です。
Private Sub dgvAdditionalInfo_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvAdditionalInfo.CellValueChanged
Dim currentCell As DataGridViewCell
currentCell = Me.dgvAdditionalInfo.CurrentCell
If Not currentCell Is Nothing Then
If currentCell.OwningColumn.DataPropertyName = "addlInfoParentCat" Then
Dim parentTypeID As Integer = currentCell.Value
Dim currentRow As DataGridViewRow = Me.dgvAdditionalInfo.CurrentRow
Dim subtypeCell As DataGridViewComboBoxCell = currentRow.Cells.Item(1)
Dim theChildren As New List(Of ExtEventAdditionalInfoType)
theChildren = Custom_ExtEventAdditionalInfoType.GetChildrenOfThisParentOrderByTypeName(parentTypeID)
subtypeCell.DataSource = Nothing
subtypeCell.DataSource = theChildren
subtypeCell.DisplayMember = "ExtEventAdditionalInfoTypeDescr"
subtypeCell.ValueMember = "ID_ExtEventAdditionalInfoType"
End If
End If
End Sub
基本的に私が見ているのは、バインディングが初めてうまく機能するということです. 最初の列で項目を選択すると、2 番目の列に項目が正しく入力されます。DataGridView に行を追加して、このプロセスを繰り返すことができます。
問題は、2 番目の列がバインドされた後で最初の列の項目を変更しようとすると発生します。次のようなダイアログボックスの無限の文字列が表示されます。
System.ArgumentException: DataGridViewComboBoxCell 値が無効です。
なぜこれが起こっているのですか?前もって感謝します!
UPDATE CodeByMoonlight の提案は機能しているようです。
再バインドする前に、DataGridViewComboBoxCell の値をクリアします。
....
subtypeCell.DataSource = Nothing
subtypeCell.Value = Nothing 'here's the change
subtypeCell.DataSource = theChildren
....