2 つの ComboBoxColumns が互いにバインドされた Win Form に DataGridView があります。ユーザーが最初のコンボボックス列からカテゴリを選択すると、2 番目の列の値がフィルタリングされます。
最初の行を追加するとコードはうまく動作しますが、新しい行を追加して最初のコンボボックスの値が最初の行と異なると、1番目の行の子コンボボックスが更新され、例外が発生します。
これが私のコードです:
DataGridViewComboBoxColumn specCmb = new DataGridViewComboBoxColumn();
specCmb.HeaderText = "Specification";
specCmb.DataSource = specBndSource;
specCmb.DisplayMember = "specName";
dataGridView1.Columns.Add(specCmb);
SqlDataAdapter itemAdapter = new SqlDataAdapter("SELECT ItemCode, ItemName, FrgnName, U_Index FROM dbo.OITM WHERE ItemCode LIKE 'AE%'", sqlConnection);
itemAdapter.Fill(dataset, "DTF.dbo.OITM");
DataRelation rel = new DataRelation("SpecItem",
dataset.Tables["DTF_Medical.dbo.Specification"].Columns["specID"],
dataset.Tables["DTF.dbo.OITM"].Columns["U_Index"]);
dataset.Relations.Add(rel);
DataGridViewComboBoxColumn itemCodeCmb = new DataGridViewComboBoxColumn();
BindingSource itemBndSource = new BindingSource();
itemBndSource.DataSource = specBndSource;
itemBndSource.DataMember = "SpecItem";
itemCodeCmb.HeaderText = "Item Code";
itemCodeCmb.DataSource = itemBndSource;
itemCodeCmb.DisplayMember = "ItemCode";
itemCodeCmb.ValueMember = "ItemCode";
dataGridView1.Columns.Add(itemCodeCmb);
ユーザーが新しい行を追加したらすぐに、前の行の変更を保存する必要があります。助けてください)