ToolStripComboBox.SelectedItemの変更は、バインディングソースに伝播しません
-
02-10-2019 - |
質問
私のバインディングはこれとして設定されています:
_selectXAxisUnitViewModelBindingSource = new BindingSource();
_selectXAxisUnitViewModelBindingSource.DataSource = typeof(SelectXAxisUnitViewModel);
_selectedUnitComboBoxBindingSource = new BindingSource();
_selectedUnitComboBoxBindingSource.DataSource = _selectXAxisUnitViewModelBindingSource;
_selectedUnitComboBoxBindingSource.DataMember = "AvailableUnits";
_selectedUnitComboBox.ComboBox.DataSource = _selectedUnitComboBoxBindingSource;
_selectedUnitComboBox.ComboBox.DisplayMember = String.Empty;
_selectedUnitComboBox.ComboBox.ValueMember = String.Empty;
_selectedUnitComboBox.ComboBox.DataBindings.Add("SelectedItem",
_selectXAxisUnitViewModelBindingSource,
"SelectedUnit", true, DataSourceUpdateMode.OnPropertyChanged);
// this is a bug in the .Net framework: http://connect.microsoft.com/VisualStudio/feedback/details/473777/toolstripcombobox-nested-on-toolstripdropdownbutton-not-getting-bindingcontext
_selectedUnitComboBox.ComboBox.BindingContext = this.BindingContext;
プロパティ「利用可能な」は文字列のコレクションであり、「selectedunit」は文字列プロパティです。これで、ドロップダウンリストは予想どおりに入力されますが、リスト内のアイテムを選択してアイテムが拘束力のあるソースに伝播されません。私が間違っていることは何ですか?
アップデート:
ちょっとしたテストプロジェクトを作成しましたが、この問題は、別のツールストライプ項目のサブアイテムとしてToolStripComboBoxを追加すると発生します。 ToolStripitemをMenustripに直接追加すると、すべてが正常に機能します。 BindingContextは、サブアイテムとして追加されたときにToolStripComboBoxに割り当てられていません(私のコードコメントを参照)、私の修正はこれを機能させるために必要なことをしていないようです。
正しい解決策はありません
他のヒント
変えてもらえますか
_selectXAxisUnitViewModelBindingSource.DataSource = typeof(SelectXAxisUnitViewModel);
に
_selectXAxisUnitViewModelBindingSource.DataSource = new SelectXAxisUnitViewModel();
所属していません StackOverflow