c# - WinForms DataGridView throwing IndexOutOfRangeException -


first timer here on stack overflow (although i've been lurking ages).

i'm developing little application contains 2 datagridviews. second datagridview filled via binding on list of custom class objects (the user presses button , list added new element , re-binded datagridview).

the problem i'm facing when have rows in datagridview (even if it's 1 row in fact...), if happen click 1 of rows select them, visual studio pops showing me debugger, because system.indexoutofrangeexception happened.

it seems when user clicks on row, datagridview throws exception because says i'm trying access -1 index of array.

the strange fact exception thrown even if don't have event listening row selection!

actually, there no event @ listening on datagridview.

debugger isn't helping because it's throwing exception @ form constructor level (it's breaking @ application.run(new frmmain()); it's not telling me useful).

can me please?

if need code let me know, , i'll provide can.

thanks!

first of all, feedbacks.

many user @trey made me think had double check bindings.

i binding datagridviews directly lists<customtype>, , not using bindinglist.

my code before:

initialization:

list<customtype> mylist = new list<customtype>(); // populating list code, skipping because not relevant mydatagridviewexample.datasource = mylist; 

data insertion:

mylist.add(something); mydatagridviewexample.datasource = null; mydatagridviewexample.datasource = mylist; 

in way, rebinding list directly everytime updated list

my code now:

initialization:

list<customtype> mylist = new list<customtype>(); // populating list code, skipping because not relevant bindinglist<customtype> mybind = new bindinglist<customtype>(mylist); mydatagridviewexample.datasource = mybind; 

data insertion:

mylist.add(something); mybind.resetbindings(); 

in way, refreshing bindinglist , not touching directly list itself.

this seem have solved problem, edit answer if encounter other strange behaviours.

thanks again, have nice day! :)


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -