Frusterated...
Should be simple. I have several forms that all do the same thing and I re-use the same basic code in all of them. But this one form is pitching a fit.
I have a DataGridView that is able to read data I have saved in a local DB. No problems there.
When I click a column, all the records populate the text boxes in the form just fine, except the very last record. It refuses.
Here's a snippet of code. I re-use this code in three other scenerios, and have no issues at all.
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
'// Open the form in the first tab.
frmImpound.Show()
frmImpound.TabControl1.SelectedIndex = 0
'// DRIVER TAB
frmImpound.lblRev.Text = DataGridView1.Item(0, e.RowIndex).Value.ToString
frmImpound.txt_agency_case_number.Text = DataGridView1.Item(1, e.RowIndex).Value.ToString
frmImpound.txt_subj_surname.Text = DataGridView1.Item(2, e.RowIndex).Value.ToString
frmImpound.txt_subj_givenname.Text = DataGridView1.Item(3, e.RowIndex).Value.ToString
frmImpound.txt_subj_street_address.Text = DataGridView1.Item(4, e.RowIndex).Value.ToString
frmImpound.txt_subj_city.Text = DataGridView1.Item(5, e.RowIndex).Value.ToString
frmImpound.txt_subj_state.Text = DataGridView1.Item(6, e.RowIndex).Value.ToString
frmImpound.txt_subj_postal_code.Text = DataGridView1.Item(7, e.RowIndex).Value.ToString
'// ========== all the way down to this part ================
If DataGridView1.Item(52, e.RowIndex).Value.ToString = "1" Then
frmImpound.cbOther2.Checked = True
End If
frmImpound.txt_vehicle_property.Text = DataGridView1.Item(53, e.RowIndex).Value.ToString
frmImpound.txt_vehicle_damage.Text = DataGridView1.Item(54, e.RowIndex).Value.ToString
frmImpound.txtOfficer.Text = DataGridView1.Item(55, e.RowIndex).Value.ToString
frmImpound.txtAgency.Text = DataGridView1.Item(56, e.RowIndex).Value.ToString
frmImpound.txtORI.Text = DataGridView1.Item(57, e.RowIndex).Value.ToString
frmImpound.txtID.Text = DataGridView1.Item(58, e.RowIndex).Value.ToString
'// THE LINE BELOW GIVES THE ERROR, ROW #59
frmImpound.txtImpoundNumber.Text = DataGridView1.Item(59, e.RowIndex).Value.ToString
Me.Close()
End Sub
Row #59 gives the following:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
I don't get it, because my index starts at 0 and climbs to 59. When I comment out row #59, my form populates just fine. This last row is causing a problem, I don't know why. Same type of code works fine elsewhere.
Does anyone see anything wrong here? I'm sure there is, I'm not the greatest programmer in the world.