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

GridView Filter and Expanded Hierarchy

1 Answer 75 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Eddie
Top achievements
Rank 1
Eddie asked on 03 Jun 2014, 07:48 PM
I have a GridView with a second-level hierarchy. I apply a filter to the BindingSource based on the node selected on a TreeView, for example: GridViewBindingSource.Filter = "Department = '" & e.Node.Text & "'". However, if any row is expanded (i.e. showing the second-level hierarchy information) it closes when the BindingSource is filtered. I would like to have any row that is open to remain open. Is there a way to do this?

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 05 Jun 2014, 01:42 PM
Hello Eddie,

Thank you for writing.

It is necessary to store the expanded state of the row before applying the filter and after the filter operation is finished, then restore the rows expanded state. Here is a sample code snippet:
Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
    Dim expandedRows As New List(Of String)
    'store expanded rows
    For Each r As GridViewRowInfo In Me.RadGridView1.ChildRows
        If r.IsExpanded Then
            expandedRows.Add(r.Cells("ProductID").Value)
        End If
    Next
    'filter the BindingSource
    Me.ProductsBindingSource.Filter = "ProductName LIKE '%w%'"
    Me.RadGridView1.MasterTemplate.Refresh()
    'restore the expanded rows
    For Each r As GridViewRowInfo In Me.RadGridView1.ChildRows
        If expandedRows.Contains(r.Cells("ProductID").Value) Then
            r.IsExpanded = True
        End If
    Next
End Sub

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Eddie
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or