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

Keep expanded item

2 Answers 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Fit2Page
Top achievements
Rank 2
Iron
Iron
Iron
Fit2Page asked on 06 Nov 2009, 10:47 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Veli
Telerik team
answered on 11 Nov 2009, 01:54 PM
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.
0
Fit2Page
Top achievements
Rank 2
Iron
Iron
Iron
answered on 11 Nov 2009, 03:35 PM
Thanks Veli, works like a charm.
Tags
Grid
Asked by
Fit2Page
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Veli
Telerik team
Fit2Page
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or