This is a migrated thread and some comments may be shown as answers.

Select row after custom filter

3 Answers 155 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Blas
Top achievements
Rank 1
Blas asked on 15 Feb 2011, 07:08 PM
I have a grid with a custom filter, like the sample in Gridview Custom filtering. How can I select the first row in the grid after the custom filter is applied?

I've tried this code, but didn't work:

Private Sub txtBuscar_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBuscar.TextChanged
        wFirstVisibleRow = -1
        Me.gridArticulos.MasterTemplate.Refresh()
        If wFirstVisibleRow > 0 Then
            Dim wposcode As String = gridArticulos.MasterTemplate.Rows(wFirstVisibleRow).Cells(0).Value.ToString
            If wposcode <> "" Then
                Me.ArticulosSGFBindingSource.Position = Me.ArticulosSGFBindingSource.Find("CODIGO", wposcode)
            End If
        End If
  
    End Sub
  
Private Sub gridArticulos_CustomFiltering(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCustomFilteringEventArgs) Handles gridArticulos.CustomFiltering
        If String.IsNullOrEmpty(Me.txtBuscar.Text) Then
            e.Visible = True
            For i As Integer = 0 To Me.gridArticulos.ColumnCount - 1
                e.Row.Cells(i).Style.Reset()
                e.Row.InvalidateRow()
            Next
            Return
        End If
        e.Visible = False
        For i As Integer = 0 To Me.gridArticulos.ColumnCount - 1
            If i <> 2 Then
                Dim text As String = e.Row.Cells(i).Value.ToString()
                If text.IndexOf(Me.txtBuscar.Text, 0, StringComparison.InvariantCultureIgnoreCase) >= 0 Then
                    e.Visible = True
                    If wFirstVisibleRow = -1 Then
                        wFirstVisibleRow = e.Row.Index
                    End If
                    e.Row.Cells(i).Style.CustomizeFill = True
                    e.Row.Cells(i).Style.DrawFill = True
                    e.Row.Cells(i).Style.BackColor = Color.FromArgb(201, 252, 254)
  
                Else
                    e.Row.Cells(i).Style.Reset()
                    e.Row.InvalidateRow()
                End If
            End If
  
        Next
  
    End Sub

Thanks in advance

3 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 15 Feb 2011, 08:48 PM
Hello,

After you call the RadGridView.MasterTemplate.Refresh(), add the following

If Me.RadGridView1.ChildRows.Count > 0 Then
    Me.RadGridView1.ChildRows(0).IsSelected = True
    Me.RadGridView1.ChildRows(0).IsCurrent = True
End If

Hope that helps
Richard
0
Blas
Top achievements
Rank 1
answered on 16 Feb 2011, 09:01 AM
Thank you so much Richard. It works!!!!
0
Richard Slade
Top achievements
Rank 2
answered on 16 Feb 2011, 09:08 AM
You're welcome. Glad I could help
Tags
GridView
Asked by
Blas
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Blas
Top achievements
Rank 1
Share this question
or