See Also

UIElement Class  | UIElement Members

Language

Visual Basic

C#

Show All

type
Type
See Also Languages Infragistics2.Win.v7.2

GetAncestor Method

Infragistics.Win Namespace > UIElement Class : GetAncestor Method

Walks up the parent chain until it reaches the parent of the requested type. Also, if this element is of the passed in type then this elemnt will be returned.

[Visual Basic]
Public Function GetAncestor( _    ByVal type As Type _ ) As UIElement
[C#]
public UIElement GetAncestor(    Type type );

Parameters

type
Type

Return Type

UIElement that matches the requested type.

Example

This sample uses GetAncestor to determine if we have clicked a RowUIElement on an UltraWinGrid, then uses GetContext to get at the RowUIElements associated row.

[Visual Basic] 


    Imports Infragistics.Win
    Imports System.Drawing
    Imports System.Diagnostics

    Public Function GetRowCellCount(ByVal pt As Point) As Integer

        ' Determine if we clicked on a row, first get the element under the mouse.
        Dim elementUnderMouse As UIElement

            elementUnderMouse = Me.UltraGrid1.DisplayLayout.UIElement.ElementFromPoint(pt)

        If Not elementUnderMouse Is Nothing Then
            Dim elementRow As UIElement

                    elementRow = elementUnderMouse.GetAncestor(GetType(UltraWinGrid.RowUIElement))
            If Not elementRow Is Nothing Then

                ' You now have the row element to do with as you please.
                ' Get the count of the cells collection
                Dim row As UltraWinGrid.UltraGridRow = elementRow.GetContext(GetType(UltraWinGrid.UltraGridRow))
                If Not row Is Nothing Then
                    Debug.WriteLine(row.Cells.Count.ToString())
                    Return row.Cells.Count
                End If
            End If
        End If

        Return 0

    End Function

[C#] 

         
        using Infragistics.Win; 
        using System.Drawing; 
        using System.Diagnostics; 
 
        private int GetRowCellCount(Point pt) 
        { 
            // Determine if we clicked on a row 
            UIElement elementUnderMouse = this.ultraGrid1.DisplayLayout.UIElement.ElementFromPoint(pt); 
 
            if (null != elementUnderMouse) 
            { 
                UIElement elementRow = elementUnderMouse.GetAncestor(typeof(UltraWinGrid.RowUIElement )); 
 
                if (null != elementRow) 
                { 
                    // You now have the row element to do with as you please. 
                    // Get the count of the cells collection 
                    UltraWinGrid.UltraGridRow row = elementRow.GetContext(typeof(UltraWinGrid.UltraGridRow)) as UltraWinGrid.UltraGridRow ; 
 
                    if (null != row) 
                    { 
                        Debug.WriteLine(row.Cells.Count.ToString()); 
                        return row.Cells.Count; 
                    } 
                } 
            } 
 
            return 0; 
 
        }

See Also

UIElement Class  | UIElement Members

E-mail your feedback on this topic.

Opinion about our help? Take our survey.

Copyright © 1996-2007 Infragistics, Inc. All rights reserved.

Build Version: 7.2.20072.1063