Keep expanded item

3 posts, 1 answers
  1. Fit2Page
    Fit2Page avatar
    375 posts
    Member since:
    Feb 2007

    Posted 06 Nov 2009 Link to this post


    In a hierarchical datagrid with two levels I am trying to keep the edited item expanded through

    Public Sub Command_Row(ByVal Sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) 
    If (TypeOf (e.Item) Is GridDataItem) Then 
    'do the stuff here 
    e.Item.OwnerTableView.ParentItem.Expanded = True 
    End if 
    End Sub 
    Does anybody have a clue why this isn't working?


  2. Answer
    Veli avatar
    2002 posts

    Posted 11 Nov 2009 Link to this post

    Hello Fit2Page,

    Once you rebind your grid, e.Item does not hold a valid reference of your item, because the grid has rebound and items are recreated. A more recommendable approach would be to save a unique key identifying your item before rebind and then search for the item with the same key after rebinding:

    Public Sub Command_Row(ByVal Sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs)
        If (TypeOf (e.Item) Is GridDataItem) Then
        'do the stuff here
        Dim expandedItemId As Integer = CType(e.Item.OwnerTableView.ParentItem.GetDataKeyValue("ID"), Integer)
    dtgProducts.MasterTableView.FindItemByKeyValue("ID", expandedItemId).Expanded = True
    End if
    End Sub

    Best wishes,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Fit2Page
    Fit2Page avatar
    375 posts
    Member since:
    Feb 2007

    Posted 11 Nov 2009 Link to this post

    Thanks Veli, works like a charm.
Back to Top