c# - Cannot set row to be selected -


i have 1 strange problem , don't have clue how solve it. here is: have 2 forms. first form take row (with index), , data row display in form possibility edit data. time have index of row datagridview in first form. when edit data in second form , press update button, want data applied in same row in first form. here code further info:

if (datagridview.selectedrows.count == 0) {     messagebox.show("index of row must selected " + rowindex);     datagridview.rows[rowindex].selected = true; } 

now, when form2 closed want check if still have same row selected in first form, , if not, select it. on line .selected = true; error: index out of range. must non-negative , less size of collection.

messagebox above line gives me right index of row... example, datgridview have 100 rows , work row index 5. why don't understand why error "index out of range"... why can't select row again?


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -