GridPattern.GridPatternInformation.ColumnCount プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
グリッド内の列の数を取得します。
public:
property int ColumnCount { int get(); };
public int ColumnCount { get; }
member this.ColumnCount : int
Public ReadOnly Property ColumnCount As Integer
プロパティ値
グリッド内の列の合計数。
例
次の例では、グリッド構造の変更 (グリッドに対する行または列のグリッド項目の追加または削除など) に対してイベント リスナーが設定されています。
///--------------------------------------------------------------------
/// <summary>
/// Set up grid event listeners.
/// </summary>
/// <param name="targetControl">
/// The automation element of interest.
/// </param>
///--------------------------------------------------------------------
private void SetGridEventListeners(AutomationElement targetControl)
{
StructureChangedEventHandler gridStructureChangedListener =
new StructureChangedEventHandler(OnGridStructureChange);
Automation.AddStructureChangedEventHandler(
targetControl,
TreeScope.Element,
gridStructureChangedListener);
}
'''--------------------------------------------------------------------
''' <summary>
''' Set up grid event listeners.
''' </summary>
''' <param name="targetControl">
''' The automation element of interest.
''' </param>
'''--------------------------------------------------------------------
Private Sub SetGridEventListeners( _
ByVal targetControl As AutomationElement)
Dim gridStructureChangedListener As StructureChangedEventHandler = _
AddressOf OnGridStructureChange
Automation.AddStructureChangedEventHandler( _
targetControl, TreeScope.Element, gridStructureChangedListener)
End Sub
///--------------------------------------------------------------------
/// <summary>
/// Event handler for grid structure change.
/// </summary>
/// <param name="src">Object that raised the event.</param>
/// <param name="e">Event arguments.</param>
///--------------------------------------------------------------------
private void OnGridStructureChange(
object src, StructureChangedEventArgs e)
{
// Make sure the element still exists. Elements such as tooltips
// can disappear before the event is processed.
AutomationElement sourceElement;
try
{
sourceElement = src as AutomationElement;
}
catch (ElementNotAvailableException)
{
return;
}
GridPattern gridPattern = GetGridPattern(sourceElement);
if (gridPattern == null)
{
return;
}
if (gridPattern.Current.ColumnCount != columnCount)
{
// Column item added.
}
else if (gridPattern.Current.RowCount != rowCount)
{
// Row item added.
}
}
// Member variables to track current row and column counts.
private int columnCount = 0;
private int rowCount = 0;
///--------------------------------------------------------------------
/// <summary>
/// Handles our application shutdown.
/// </summary>
/// <param name="args">Event arguments.</param>
///--------------------------------------------------------------------
protected override void OnExit(System.Windows.ExitEventArgs args)
{
Automation.RemoveAllEventHandlers();
base.OnExit(args);
}
'''--------------------------------------------------------------------
''' <summary>
''' Event handler for grid structure change.
''' </summary>
''' <param name="src">Object that raised the event.</param>
''' <param name="e">Event arguments.</param>
'''--------------------------------------------------------------------
Private Sub OnGridStructureChange( _
ByVal src As Object, ByVal e As StructureChangedEventArgs)
' Make sure the element still exists. Elements such as tooltips
' can disappear before the event is processed.
Dim sourceElement As AutomationElement
Try
sourceElement = DirectCast(src, AutomationElement)
Catch exc As ElementNotAvailableException
Return
End Try
Dim gridPattern As GridPattern = GetGridPattern(sourceElement)
If gridPattern Is Nothing Then
Return
End If
If gridPattern.Current.ColumnCount <> columnCount Then
' Column item added.
ElseIf gridPattern.Current.RowCount <> rowCount Then
' Row item added.
End If
End Sub
' Member variables to track current row and column counts.
Private columnCount As Integer = 0
Private rowCount As Integer = 0
'''--------------------------------------------------------------------
''' <summary>
''' Handles our application shutdown.
''' </summary>
''' <param name="args">Event arguments.</param>
'''--------------------------------------------------------------------
Protected Overrides Sub OnExit( _
ByVal args As System.Windows.ExitEventArgs)
Automation.RemoveAllEventHandlers()
MyBase.OnExit(args)
End Sub
///--------------------------------------------------------------------
/// <summary>
/// Obtains a GridPattern control pattern from an
/// automation element.
/// </summary>
/// <param name="targetControl">
/// The automation element of interest.
/// </param>
/// <returns>
/// A GridPattern object.
/// </returns>
///--------------------------------------------------------------------
private GridPattern GetGridPattern(
AutomationElement targetControl)
{
GridPattern gridPattern = null;
try
{
gridPattern =
targetControl.GetCurrentPattern(
GridPattern.Pattern)
as GridPattern;
}
// Object doesn't support the
// GridPattern control pattern
catch (InvalidOperationException)
{
return null;
}
return gridPattern;
}
'''--------------------------------------------------------------------
''' <summary>
''' Obtains a GridPattern control pattern from an
''' automation element.
''' </summary>
''' <param name="targetControl">
''' The automation element of interest.
''' </param>
''' <returns>
''' A GridPattern object.
''' </returns>
'''--------------------------------------------------------------------
Private Function GetGridPattern( _
ByVal targetControl As AutomationElement) As GridPattern
Dim gridPattern As GridPattern = Nothing
Try
gridPattern = DirectCast( _
targetControl.GetCurrentPattern( _
gridPattern.Pattern), GridPattern)
Catch exc As InvalidOperationException
' Object doesn't support the
' GridPattern control pattern
Return Nothing
End Try
Return gridPattern
End Function 'GetGridPattern
注釈
プロバイダーの実装によっては、非表示の行と列がUI オートメーション ツリーに読み込まれる可能性があるため、 プロパティと ColumnCount プロパティにRowCount反映されます。 非表示の行と列がまだ読み込まれていない場合、それらはカウントされません。
既定値は 0 です。
適用対象
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET