Keep expanded item

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

    Posted 06 Nov 2009 Link to this post

    Hi,

    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 
     
    dtgProducts.ReBind() 
    e.Item.OwnerTableView.ParentItem.Expanded = True 
    End if 
     
    End Sub 
    Does anybody have a clue why this isn't working?

    Marc






  2. Answer
    Veli
    Admin
    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.Rebind()
     
    dtgProducts.MasterTableView.FindItemByKeyValue("ID", expandedItemId).Expanded = True
    End if
      
    End Sub


    Best wishes,
    Veli
    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. UI for ASP.NET Ajax is Ready for VS 2017
  4. Fit2Page
    Fit2Page avatar
    345 posts
    Member since:
    Feb 2007

    Posted 11 Nov 2009 Link to this post

    Thanks Veli, works like a charm.
Back to Top