0

The below code should search DataGridView1 which is on the LeaderAccessTable form for an integer that the user inputs into SendFromID, if the DataGridView1's first column contains what the integer that the user has entered into SendFromID then the entire row should be selected. However it doesn't select any rows at all... Can anyone see why? This code is ran from a separate form.

Dim intcount As Integer
For Each Row As DataGridViewRow In LeadersAccessTable.DataGridView1.Rows
  If LeadersAccessTable.DataGridView1.Rows(intcount).Cells(0).Value.ToString = SendFromID.Text Then
    LeadersAccessTable.DataGridView1.Rows(intcount).Selected = True
  End If
Next
MsgBox("Done.")
OneFineDay
  • 9,004
  • 3
  • 26
  • 37
user3224987
  • 83
  • 3
  • 12
  • It's likely a problem that your not referring to the instance of the form which has the data not the {formname}.{controlname} reference - which is legal to call, but gets you no where. – OneFineDay Jan 25 '14 at 20:27

1 Answers1

0

In the end this code worked.

Dim v_SelectRow As Integer
        For counter = 0 To (LeadersAccessTable.DataGridView1.Rows.Count - 1)
            For counter2 = 0 To (LeadersAccessTable.DataGridView1.Columns.Count - 1)
                If (LeadersAccessTable.DataGridView1.Rows(counter).Cells(0).Value.ToString.Contains(SendFromID.Text)) Then
                    LeadersAccessTable.DataGridView1.Rows(counter).Cells(0).Selected = True
                    v_SelectRow = LeadersAccessTable.DataGridView1.CurrentRow.Index
                    CurrentPoints.Text = LeadersAccessTable.DataGridView1.Item(8, v_SelectRow).Value
                    'Do Something
                    Else
                    'Do Something
                    End If
                Next
            Next
user3224987
  • 83
  • 3
  • 12