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

child / parent cell value

6 Answers 334 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Karl
Top achievements
Rank 1
Karl asked on 09 Jul 2010, 10:25 PM
If the current row is a childrow, how do you get a value of a cell of its parentrow?
thanks
karl

6 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 15 Jul 2010, 09:18 AM
Hello Karl Golling,

Thank you for writing.

You can access the parent row through the ViewInfo.ParentRow property. Please consider the following code:
 
GridViewDataRowInfo row = this.radGridView1.CurrentRow as GridViewDataRowInfo;
if (row != null && row.ParentRow != null)
{
    object cellValue = row.ViewInfo.ParentRow.Cells["OrderID"].Value;
}

Hope this helps. Let me know if you have any other questions.

Greetings,
Martin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Karl
Top achievements
Rank 1
answered on 23 Jul 2010, 10:13 PM
Thanks!
0
Jeff
Top achievements
Rank 1
answered on 16 Mar 2014, 04:16 AM
This no longer works. ParentRow has been deprecated and replaced by Parent, which does not have the Cells property nor any other useful properties. How does this work now?
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 19 Mar 2014, 02:27 PM
Hello Jeff,

Thank you for contacting Telerik Support.

Here is a sample code snippet, demonstrating how to access the parent row's cell's value from the child row. Note that the Parent property is of type IHierarchicalRow. For the master row, the parent is the MasterGridViewTemplate. However, for the child rows the parent is the parent GridViewDataRowInfo. That is why it is necessary to cast the property in order to access the desired properties:
private void radGridView1_CurrentRowChanged(object sender, CurrentRowChangedEventArgs e)
{
    if (e.CurrentRow != null)
    {
        MasterGridViewTemplate masterTemplate = e.CurrentRow.Parent as MasterGridViewTemplate;
        if (masterTemplate != null)
        {
            //CurrentRow is from the master level
        }
 
        GridViewDataRowInfo parentRow = e.CurrentRow.Parent as GridViewDataRowInfo;
        if (parentRow != null)
        {
            //CurrentRow is from the child template
            object cellValue = parentRow.Cells[0].Value;
        }
    }
}

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

Regards,
Desislava
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
0
Eddie
Top achievements
Rank 1
answered on 26 May 2014, 08:09 PM
How would this code look for VB?
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 29 May 2014, 10:50 AM
Hello Eddie,

Thank you for writing.

Here is the code snippet in VB.NET:
Private Sub RadGridView1_CurrentRowChanged(sender As Object, e As CurrentRowChangedEventArgs) _
Handles RadGridView1.CurrentRowChanged
    If e.CurrentRow IsNot Nothing Then
        Dim masterTemplate As MasterGridViewTemplate = TryCast(e.CurrentRow.Parent, MasterGridViewTemplate)
        If masterTemplate IsNot Nothing Then
            'CurrentRow is from the master level
            Dim cellValue As Object = e.CurrentRow.Cells(0).Value
        End If
    End If
 
    Dim parentRow As GridViewDataRowInfo = TryCast(e.CurrentRow.Parent, GridViewDataRowInfo)
    If parentRow IsNot Nothing Then
        'CurrentRow is from the child template
        Dim cellValue As Object = parentRow.Cells(0).Value
    End If
End Sub

Feel free to use our online Code Converter for your convenience.

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
Karl
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Karl
Top achievements
Rank 1
Jeff
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Eddie
Top achievements
Rank 1
Share this question
or