목록 데이터 소스에 바인딩하는 ComboBox가 있습니다. 목록은 비어있는 상태에서 시작하여 나중에 항목을 추가하려고합니다. 문제는 첫 번째 항목을 추가 할 때 ArgumentOutOfRangeException이 발생한다는 것입니다. InvalidArgument = '0'값이 'SelectedIndex'에 유효하지 않습니다. 누구든지 해결할 수 있습니까?빈 목록을 ComboBox에 바인딩하고 나중에 항목을 추가하는 방법은 무엇입니까?
정확히 똑같은 문제가 여기에 설명되어 있지만 해결되었는지 확실하지 않습니다.
BindingList<int> bl = new BindingList<int>();
BindingSource bs = new BindingSource();
ComboBox cb = new ComboBox();
this.Controls.Add(cb);
cb.DataSource = bs;
bs.DataSource = bl;
//bs.DataError += delegate { throw new Exception("DataError"); };
bl.Add(99);
그리고 그 결과 스택 추적 : 여기
combobox--bindingsource-possible-bug
은 해당 게시물에서 코드System.Windows.Forms.dll!System.Windows.Forms.ComboBox.SelectedIndex.set(int value) + 0x1e8 bytes
System.Windows.Forms.dll!System.Windows.Forms.ListControl.DataManager_PositionChanged(object sender, System.EventArgs e) + 0x36 bytes
System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.OnPositionChanged(System.EventArgs e) + 0x39 bytes
System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.ChangeRecordState(int newPosition, bool validating, bool endCurrentEdit, bool firePositionChange, bool pullData) + 0x16a bytes
System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.List_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e) + 0x2f9 bytes
System.Windows.Forms.dll!System.Windows.Forms.BindingSource.OnListChanged(System.ComponentModel.ListChangedEventArgs e) + 0x82 bytes
System.Windows.Forms.dll!System.Windows.Forms.BindingSource.InnerList_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e) + 0x2e bytes
System.dll!System.ComponentModel.BindingList<int>.OnListChanged(System.ComponentModel.ListChangedEventArgs e) + 0x17 bytes
System.dll!System.ComponentModel.BindingList<int>.InsertItem(int index, int item) + 0x62 bytes
mscorlib.dll!System.Collections.ObjectModel.Collection<int>.Add(int item) + 0x36 bytes
WindowsFormsApplication1.exe!WindowsFormsApplication1.Form1.button1_Click(object sender, System.EventArgs e) Line 35 + 0x10 bytes C#
나는 WPF와 함께 작업하지만, 나는 ObservableCollection에 바인드하고 비어 나중에 항목을 추가한다. – Paparazzi
@Blam 만 WPF를 사용하고 있었다면 – Yatrix