TablePattern.TablePatternInformation.GetRowHeaders 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
擷取資料表中所有資料列行首的 AutomationElement 集合。
public:
cli::array <System::Windows::Automation::AutomationElement ^> ^ GetRowHeaders();
public System.Windows.Automation.AutomationElement[] GetRowHeaders ();
member this.GetRowHeaders : unit -> System.Windows.Automation.AutomationElement[]
Public Function GetRowHeaders () As AutomationElement()
傳回
AutomationElement 的集合。 預設值為空白陣列。
範例
在下列範例中,會擷取特定資料表專案的資料列或資料行標頭。
為了本範例的目的,會示範 屬性與資料列和資料行標頭專案之間的 RowOrColumnMajor 關聯性。 不過,不論資料表的 屬性為何,資料表都可以有資料列和資料行標頭 RowOrColumnMajor 。
///--------------------------------------------------------------------
/// <summary>
/// Obtains a table items primary row or column header.
/// </summary>
/// <param name="tableItem">
/// The table item of interest.
/// </param>
/// <returns>
/// The table item header.
/// </returns>
///--------------------------------------------------------------------
private AutomationElement GetTableItemHeader(TableItemPattern tableItem)
{
if (tableItem == null)
{
throw new ArgumentException("Target element cannot be null.");
}
TablePattern tablePattern = GetTablePattern(tableItem.Current.ContainingGrid);
if (tablePattern == null)
{
return null;
}
AutomationElement[] tableHeaders =
GetPrimaryHeaders(tablePattern);
if (tableHeaders == null)
{
// Indeterminate headers.
return null;
}
if (tablePattern.Current.RowOrColumnMajor == RowOrColumnMajor.ColumnMajor)
{
return tableHeaders[tableItem.Current.Column];
}
if (tablePattern.Current.RowOrColumnMajor == RowOrColumnMajor.RowMajor)
{
return tableHeaders[tableItem.Current.Row];
}
return null;
}
///--------------------------------------------------------------------
/// <summary>
/// Obtains an array of table headers.
/// </summary>
/// <param name="tablePattern">
/// The TablePattern object of interest.
/// </param>
/// <returns>
/// The table row or column primary headers.
/// </returns>
///--------------------------------------------------------------------
private AutomationElement[] GetPrimaryHeaders(
TablePattern tablePattern)
{
if (tablePattern.Current.RowOrColumnMajor ==
RowOrColumnMajor.RowMajor)
{
return tablePattern.Current.GetRowHeaders();
}
if (tablePattern.Current.RowOrColumnMajor ==
RowOrColumnMajor.ColumnMajor)
{
return tablePattern.Current.GetColumnHeaders();
}
return null;
}
'''--------------------------------------------------------------------
''' <summary>
''' Obtains a table items primary row or column header.
''' </summary>
''' <param name="tableItem">
''' The table item of interest.
''' </param>
''' <returns>
''' The table item header.
''' </returns>
'''--------------------------------------------------------------------
Private Function GetTableItemHeader( _
ByVal tableItem As TableItemPattern) As AutomationElement
If tableItem Is Nothing Then
Throw New ArgumentException("Target element cannot be null.")
End If
Dim tablePattern As TablePattern = _
GetTablePattern(tableItem.Current.ContainingGrid)
If tablePattern Is Nothing Then
Return Nothing
End If
Dim tableHeaders As AutomationElement() = _
GetPrimaryHeaders(tablePattern)
If tableHeaders Is Nothing Then
' Indeterminate headers.
Return Nothing
End If
If tablePattern.Current.RowOrColumnMajor = _
RowOrColumnMajor.ColumnMajor Then
Return tableHeaders(tableItem.Current.Column)
End If
If tablePattern.Current.RowOrColumnMajor = _
RowOrColumnMajor.RowMajor Then
Return tableHeaders(tableItem.Current.Row)
End If
Return Nothing
End Function 'GetTableItemHeader
'''--------------------------------------------------------------------
''' <summary>
''' Obtains an array of table headers.
''' </summary>
''' <param name="tablePattern">
''' The TablePattern object of interest.
''' </param>
''' <returns>
''' The table primary row or column headers.
''' </returns>
'''--------------------------------------------------------------------
Private Overloads Function GetPrimaryHeaders( _
ByVal tablePattern As TablePattern) As AutomationElement()
If tablePattern.Current.RowOrColumnMajor = _
RowOrColumnMajor.RowMajor Then
Return tablePattern.Current.GetRowHeaders()
End If
If tablePattern.Current.RowOrColumnMajor = _
RowOrColumnMajor.ColumnMajor Then
Return tablePattern.Current.GetColumnHeaders()
End If
Return Nothing
End Function 'GetPrimaryHeaders