When selecting from DataGridView as program line below:

Diameter = DesignationsDataGridView.Rows(e.RowIndex).Cells(0).Value

I get following exception message box:-

System.ArgumentOutOfRangeException was unhandled
Message="Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"

If I select 'continue' from message box then I return to datagridview for further attempt.

Please can anyone tell me how to deal with this exception? (other than not to click on header, of course)

If e.RowIndex.ToString > -1 Then
Diameter = DesignationsDataGridView.Rows(e.RowIndex).Cells(0).Value
endif

That did it, thanks Oussama.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.