GridPattern.GetItem(Int32, Int32) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 셀을 나타내는 AutomationElement를 검색합니다.
public:
System::Windows::Automation::AutomationElement ^ GetItem(int row, int column);
public System.Windows.Automation.AutomationElement GetItem (int row, int column);
member this.GetItem : int * int -> System.Windows.Automation.AutomationElement
Public Function GetItem (row As Integer, column As Integer) As AutomationElement
매개 변수
- row
- Int32
관심 있는 행의 서수입니다.
- column
- Int32
관심 있는 열의 서수입니다.
반환
검색된 셀을 나타내는 AutomationElement입니다.
예외
예제
다음 예제에서는 AutomationFocusChangedEvent 표 컨테이너 내 모눈 항목의 이동을 추적 하려면 수신기를 선언 합니다. 항목 속성은 각 포커스 변경 이벤트 시 콘솔에 표시 됩니다.
///--------------------------------------------------------------------
/// <summary>
/// Set up grid item event listeners.
/// </summary>
/// <param name="targetControl">
/// The grid item container of interest.
/// </param>
///--------------------------------------------------------------------
private void SetGridItemEventListeners(AutomationElement targetControl)
{
AutomationFocusChangedEventHandler gridItemFocusChangedListener =
new AutomationFocusChangedEventHandler(OnGridItemFocusChange);
Automation.AddAutomationFocusChangedEventHandler(
gridItemFocusChangedListener);
}
'''--------------------------------------------------------------------
''' <summary>
''' Set up grid item event listeners.
''' </summary>
''' <param name="targetControl">
''' The grid item container of interest.
''' </param>
'''--------------------------------------------------------------------
Private Sub SetGridItemEventListeners( _
ByVal targetControl As AutomationElement)
Dim gridItemFocusChangedListener As AutomationFocusChangedEventHandler = _
AddressOf OnGridItemFocusChange
Automation.AddAutomationFocusChangedEventHandler( _
gridItemFocusChangedListener)
End Sub
///--------------------------------------------------------------------
/// <summary>
/// Event handler for grid item focus change.
/// Can be used to track traversal of individual grid items
/// within a grid.
/// </summary>
/// <param name="src">Object that raised the event.</param>
/// <param name="e">Event arguments.</param>
///--------------------------------------------------------------------
private void OnGridItemFocusChange(
object src, AutomationFocusChangedEventArgs 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;
}
// Gets a GridItemPattern from the source of the event.
GridItemPattern gridItemPattern =
GetGridItemPattern(sourceElement);
if (gridItemPattern == null)
{
return;
}
// Gets a GridPattern from the grid container.
GridPattern gridPattern =
GetGridPattern(gridItemPattern.Current.ContainingGrid);
if (gridPattern == null)
{
return;
}
AutomationElement gridItem = null;
try
{
gridItem = gridPattern.GetItem(
gridItemPattern.Current.Row,
gridItemPattern.Current.Column);
}
catch (ArgumentOutOfRangeException)
{
// If the requested row coordinate is larger than the RowCount
// or the column coordinate is larger than the ColumnCount.
// -- OR --
// If either of the requested row or column coordinates
// are less than zero.
// TO DO: error handling.
}
// Further event processing can be done at this point.
// For the purposes of this sample we just report item properties.
StringBuilder gridItemReport = new StringBuilder();
gridItemReport.AppendLine(
gridItemPattern.Current.Row.ToString()).AppendLine(
gridItemPattern.Current.Column.ToString()).AppendLine(
gridItemPattern.Current.RowSpan.ToString()).AppendLine(
gridItemPattern.Current.ColumnSpan.ToString()).AppendLine(
gridItem.Current.AutomationId.ToString());
Console.WriteLine(gridItemReport.ToString());
}
///--------------------------------------------------------------------
/// <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 item focus change.
''' Can be used to track traversal of individual grid items
''' within a grid.
''' </summary>
''' <param name="src">Object that raised the event.</param>
''' <param name="e">Event arguments.</param>
'''--------------------------------------------------------------------
Private Sub OnGridItemFocusChange( _
ByVal src As Object, ByVal e As AutomationFocusChangedEventArgs)
' 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
' Gets a GridItemPattern from the source of the event.
Dim gridItemPattern As GridItemPattern = _
GetGridItemPattern(sourceElement)
If gridItemPattern Is Nothing Then
Return
End If
' Gets a GridPattern from the grid container.
Dim gridPattern As GridPattern = _
GetGridPattern(gridItemPattern.Current.ContainingGrid)
If gridPattern Is Nothing Then
Return
End If
Dim gridItem As AutomationElement = Nothing
Try
gridItem = gridPattern.GetItem( _
gridItemPattern.Current.Row, gridItemPattern.Current.Column)
Catch
' If the requested row coordinate is larger than the RowCount
' or the column coordinate is larger than the ColumnCount.
' -- OR --
' If either of the requested row or column coordinates
' are less than zero.
' TO DO: error handling.
End Try
' Further event processing can be done at this point.
' For the purposes of this sample we just report item properties.
Dim gridItemReport As New StringBuilder()
gridItemReport.AppendLine( _
gridItemPattern.Current.Row.ToString()).AppendLine( _
gridItemPattern.Current.Column.ToString()).AppendLine( _
gridItemPattern.Current.RowSpan.ToString()).AppendLine( _
gridItemPattern.Current.ColumnSpan.ToString()).AppendLine( _
gridItem.Current.AutomationId.ToString())
Console.WriteLine(gridItemReport.ToString())
End Sub
'''--------------------------------------------------------------------
''' <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
설명
Grid 좌표는 좌표가 (0, 0) 왼쪽 위 (또는 오른쪽 상단 셀 로캘에 따라)를 사용 하 여 0부터 시작 합니다.
셀이 비어 있으면 해당 셀에 대한 속성 검색 ContainingGrid 을 지원하기 위해 UI 자동화 요소가 여전히 반환됩니다. 표의 자식 요소의 레이아웃은 다음과 같이 비정형된 배열과 유사한 경우 이것이 가능 합니다.
비어 있는 좌표에서 표 컨트롤의 예
적용 대상
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET