Windows DataGridView BindingSource Index Beyond Exception

Scenario:

I basically have

  • System.Windows.Forms.DataGridView

  • Class inheriting from BindingSource and IBindingList

  • A class that has 2 standard lists as private properties

DataGridView dgv = new ...

MyBindingSource bindingSource = new ...

MyList List = New ...

The DataGridView.DataSource property is set to BindingSource, and BindingSource.DataSource is set to one of the private List.

bindingSource.DataSource = list.ListA;

dgv.DataSource = bindingSource;

I get a bunch of information coming from the database, and I convert the information into objects and add it to MyList one at a time and at the end should be displayed in the DataGridView.

, , : ( bindings) , DataGridView. , , - 1 DataGridView.DataSource bindingSource. , , , datagridview , .

, List notifiy BindingSource, DataGridView, , . , IndexOutOfrange, : "Item at index -1 ". BindingSource, , -1, Current . BindingSource , .

, , , ? , , , , "CurrencyManager" - . , base.OnDataMemberChanged base.OnListChanged .

: , , datagrid, . , DataGridView BindingSource

+3
3

DataSource , DataGridView SelectionChanged , . , , , SelectionChanged , . : Rows.count 0 datagrid.

+2

ObservableCollection? , , , , , . ( )

,

+1
+1

Source: https://habr.com/ru/post/1734350/


All Articles