ListViewItem.GetSubItemAt(Int32, Int32) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 좌표에 있는 ListViewItem 하위 항목의 값을 반환합니다.
public:
System::Windows::Forms::ListViewItem::ListViewSubItem ^ GetSubItemAt(int x, int y);
public System.Windows.Forms.ListViewItem.ListViewSubItem GetSubItemAt(int x, int y);
public System.Windows.Forms.ListViewItem.ListViewSubItem? GetSubItemAt(int x, int y);
member this.GetSubItemAt : int * int -> System.Windows.Forms.ListViewItem.ListViewSubItem
Public Function GetSubItemAt (x As Integer, y As Integer) As ListViewItem.ListViewSubItem
매개 변수
- x
- Int32
X 좌표입니다.
- y
- Int32
Y 좌표입니다.
반품
ListViewItem.ListViewSubItem 지정된 x 좌표 및 y 좌표입니다.
예제
다음 코드 예제에서는 메서드를 사용 하는 방법을 보여 줍니다 GetSubItemAt . 이 코드를 실행하려면 Windows Form에 붙여넣고 양식의 생성자 또는 InitializeListView1 이벤트 처리 메서드에서 Load 호출합니다.
private ListView listView1;
private void InitializeListView1(){
listView1 = new ListView();
// Set the view to details to show subitems.
listView1.View = View.Details;
// Add some columns and set the width.
listView1.Columns.Add("Name");
listView1.Columns.Add("Number");
listView1.Columns.Add("Description");
listView1.Width = 175;
// Create some items and subitems; add the to the ListView.
ListViewItem item1 = new ListViewItem("Widget");
item1.SubItems.Add(new ListViewItem.ListViewSubItem(item1, "14"));
item1.SubItems.Add(new ListViewItem.ListViewSubItem(item1,
"A description of Widget"));
ListViewItem item2 = new ListViewItem("Bracket");
item2.SubItems.Add(new ListViewItem.ListViewSubItem(item2, "8"));
listView1.Items.Add(item1);
listView1.Items.Add(item2);
// Add the ListView to the form.
this.Controls.Add(listView1);
listView1.MouseDown += new MouseEventHandler(listView1_MouseDown);
}
void listView1_MouseDown(object sender, MouseEventArgs e)
{
// Get the item at the mouse pointer.
ListViewHitTestInfo info = listView1.HitTest(e.X, e.Y);
ListViewItem.ListViewSubItem subItem = null;
// Get the subitem 120 pixels to the right.
if (info != null)
if (info.Item != null)
subItem = info.Item.GetSubItemAt(e.X + 120, e.Y);
// Show the text of the subitem, if found.
if (subItem != null)
MessageBox.Show(subItem.Text);
}
Private WithEvents listView1 As ListView
Private Sub InitializeListView1()
listView1 = New ListView()
' Set the view to details to show subitems.
listView1.View = View.Details
' Add some columns and set the width.
listView1.Columns.Add("Name")
listView1.Columns.Add("Number")
listView1.Columns.Add("Description")
listView1.Width = 175
' Create some items and subitems; add the to the ListView.
Dim item1 As New ListViewItem("Widget")
item1.SubItems.Add(New ListViewItem.ListViewSubItem(item1, "14"))
item1.SubItems.Add(New ListViewItem.ListViewSubItem(item1, "A description of Widget"))
Dim item2 As New ListViewItem("Bracket")
item2.SubItems.Add(New ListViewItem.ListViewSubItem(item2, "8"))
listView1.Items.Add(item1)
listView1.Items.Add(item2)
' Add the ListView to the form.
Me.Controls.Add(listView1)
End Sub
Private Sub listView1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
' Get the item at the mouse pointer.
Dim info As ListViewHitTestInfo = listView1.HitTest(e.X, e.Y)
Dim subItem As ListViewItem.ListViewSubItem = Nothing
' Get the subitem 120 pixels to the right.
If (info IsNot Nothing) Then
If (info.Item IsNot Nothing) Then
subItem = info.Item.GetSubItemAt(e.X + 120, e.Y)
End If
End If ' Show the text of the subitem, if found.
If (subItem IsNot Nothing) Then
MessageBox.Show(subItem.Text)
End If
End Sub
설명
메서드가 GetSubItemAt 뷰에 nullListView 없거나 지정된 지점에 위치하지 않은 Details 경우 반환 ListViewItem.ListViewSubItem 됩니다.