FiascoQdos 0 Newbie Poster

Hi people, I was hoping someone out there could help me out as Ive been going mad with this problem of trying to filter data and show the 2nd row in the datagrid data in textboxes (I have it partially working).

Well basically I can highlight the first row and show the data in textboxes which is perfect, but I struggle to do the same with the 2nd row (However I have the coding which selects the 2nd row). My coding is as follows:

Private Sub firstrow()

If dgmerits.CurrentRowIndex > -1 Then
Me.ID = CType(dgmerits.Item(dgmerits().CurrentRowIndex, 0), Int32)


Else
MessageBox.Show("Sorry, No student found matching your search.", "No student found", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.txtsearch.Text = Me.txtsearch.Text.Substring(0, Me.txtsearch.TextLength - 1)
Me.txtsearch.SelectionLength = 0
Me.txtsearch.SelectionStart = Me.txtsearch.TextLength
Me.txtsearch.Focus()
End If
dgmerits.Select(0)
End Sub


Private Sub secondrow()
Try
dgmerits.Select(1)
dgmerits.SelectionBackColor = Color.LightCoral
Catch ex As Exception
Try
dgmerits.Select(0)
dgmerits.SelectionBackColor = Color.LightCoral
Catch ex1 As Exception
MessageBox.Show("No rows to select")
End Try
End Try


End Sub


Private Sub txtsearch_TextChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearch.TextChanged
Dim dvfilter As DataView = Nothing
If TypeOf dgmerits.DataSource Is DataView Then
dvfilter = CType(dgmerits.DataSource, DataView)


ElseIf TypeOf dgmerits.DataSource Is DataTable Then
dvfilter = CType(dgmerits.DataSource, DataTable).DefaultView
End If


If txtsearch.TextLength > 0 Then
dvfilter.RowFilter = String.Format("PupilNumber LIKE '{0}*' ", txtsearch.Text)
Else
dvfilter.RowFilter = ""
End If


dgmerits.DataSource = dvfilter
Firstrow
SecondRow
End Sub

Now where it says Firstrow Secondrow in the txtsearch - Both work but Secondrow does not show the data in the textboxes, any ideas to maybe why?

Please help me as Ive been struggling on this all week.

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.