0

I'm doing a simple datagridview update function

I have 2 forms. 1 for datagridview and another for the textboxes for update purpose.

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

Additional information: Index was out of range. Must be non-negative and less than the size of the collection.

The error was thrown at this code

Form1.DataGridView1.SelectedRows(0).Cells(3).Value = txtName.Text

But in Form1 i have a code that takes the current data in datagridview and it works perfectly.

Dim name As String = DataGridView1.SelectedRows(0).Cells(3).Value.ToString
Form2.txtName.Text = name
Community
  • 1
  • 1
  • 1
    That first code snippet is referring to the default instance of `Form1`. My guess is that the instance of `Form1` that you're looking at is not the default instance, therefore you're referring to a different `Form1` instance in which no rows are selected. This is why so many experienced developers hate default instances. – jmcilhinney Feb 17 '17 at 03:53
  • I meant exactly what I said. What did you not understand about the information you found when you Googled "default instance"? – jmcilhinney Feb 17 '17 at 04:31

0 Answers0