ListView.TopItem 속성

정의

컨트롤에 가장 먼저 표시되는 항목을 가져오거나 설정합니다.

public:
 property System::Windows::Forms::ListViewItem ^ TopItem { System::Windows::Forms::ListViewItem ^ get(); };
public:
 property System::Windows::Forms::ListViewItem ^ TopItem { System::Windows::Forms::ListViewItem ^ get(); void set(System::Windows::Forms::ListViewItem ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.ListViewItem TopItem { get; }
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.ListViewItem TopItem { get; set; }
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.ListViewItem? TopItem { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.TopItem : System.Windows.Forms.ListViewItem
[<System.ComponentModel.Browsable(false)>]
member this.TopItem : System.Windows.Forms.ListViewItem with get, set
Public ReadOnly Property TopItem As ListViewItem
Public Property TopItem As ListViewItem

속성 값

컨트롤에서 첫째 표시 가능 항목을 나타내는 ListViewItem입니다.

특성

예외

속성은 View , SmallIcon또는 TileLargeIcon설정됩니다.

예제

다음 코드 예제를 사용 하 여 개체의 ListViewItem 하위 항목의 스타일을 다시 설정 하는 방법을 보여 TopItem 줍니다는 속성 및 ListViewItem.ListViewSubItem.ResetStyle 메서드. 예제를 실행하려면 다음 코드를 라는 Button1 단추가 포함된 폼에 붙여넣고 폼의 생성자 또는 Load 이벤트 처리기에서 메서드를 호출 InitializeListView 합니다.

internal:
   // Declare the Listview object.
   System::Windows::Forms::ListView^ myListView;

private:

   // Initialize the ListView object with subitems of a different
   // style than the default styles for the ListView.
   void InitializeListView()
   {
      // Set the Location, View and Width properties for the 
      // ListView object. 
      myListView = gcnew ListView;
      myListView->Location = System::Drawing::Point( 20, 20 );
      myListView->Width = 250;
      
      // The View property must be set to Details for the 
      // subitems to be visible.
      myListView->View = View::Details;
      
      // Each SubItem object requires a column, so add three columns.
      this->myListView->Columns->Add( "Key", 50, HorizontalAlignment::Left );
      this->myListView->Columns->Add( "A", 100, HorizontalAlignment::Left );
      this->myListView->Columns->Add( "B", 100, HorizontalAlignment::Left );
      
      // Add a ListItem object to the ListView.
      ListViewItem^ entryListItem = myListView->Items->Add( "Items" );
      
      // Set UseItemStyleForSubItems property to false to change 
      // look of subitems.
      entryListItem->UseItemStyleForSubItems = false;
      
      // Add the expense subitem.
      ListViewItem::ListViewSubItem ^ expenseItem = entryListItem->SubItems->Add( "Expense" );
      
      // Change the expenseItem object's color and font.
      expenseItem->ForeColor = System::Drawing::Color::Red;
      expenseItem->Font = gcnew System::Drawing::Font( "Arial",10,System::Drawing::FontStyle::Italic );
      
      // Add a subitem called revenueItem 
      ListViewItem::ListViewSubItem ^ revenueItem = entryListItem->SubItems->Add( "Revenue" );
      
      // Change the revenueItem object's color and font.
      revenueItem->ForeColor = System::Drawing::Color::Blue;
      revenueItem->Font = gcnew System::Drawing::Font( "Times New Roman",10,System::Drawing::FontStyle::Bold );
      
      // Add the ListView to the form.
      this->Controls->Add( this->myListView );
   }

   void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      // Use the ListView.TopItem property to access the SubItems
      // and then reset their appearance.
      myListView->TopItem->SubItems[ 1 ]->ResetStyle();
      myListView->TopItem->SubItems[ 2 ]->ResetStyle();
   }

// Declare the Listview object.
internal System.Windows.Forms.ListView myListView;

// Initialize the ListView object with subitems of a different
// style than the default styles for the ListView.
private void InitializeListView()
{

    // Set the Location, View and Width properties for the 
    // ListView object. 
    myListView = new ListView();
    myListView.Location = new System.Drawing.Point(20, 20);
    myListView.Width = 250;

    // The View property must be set to Details for the 
    // subitems to be visible.
    myListView.View = View.Details;
    
    // Each SubItem object requires a column, so add three columns.
    this.myListView.Columns.Add("Key", 50, HorizontalAlignment.Left);
    this.myListView.Columns.Add("A", 100, HorizontalAlignment.Left);
    this.myListView.Columns.Add("B", 100, HorizontalAlignment.Left);

    // Add a ListItem object to the ListView.
    ListViewItem entryListItem = myListView.Items.Add("Items");

    // Set UseItemStyleForSubItems property to false to change 
    // look of subitems.
    entryListItem.UseItemStyleForSubItems = false;

    // Add the expense subitem.
    ListViewItem.ListViewSubItem expenseItem = 
        entryListItem.SubItems.Add("Expense");

    // Change the expenseItem object's color and font.
    expenseItem.ForeColor = System.Drawing.Color.Red;
    expenseItem.Font = new System.Drawing.Font(
        "Arial", 10, System.Drawing.FontStyle.Italic);

    // Add a subitem called revenueItem 
    ListViewItem.ListViewSubItem revenueItem = 
        entryListItem.SubItems.Add("Revenue");

    // Change the revenueItem object's color and font.
    revenueItem.ForeColor = System.Drawing.Color.Blue;
    revenueItem.Font = new System.Drawing.Font(
        "Times New Roman", 10, System.Drawing.FontStyle.Bold);

    // Add the ListView to the form.
    this.Controls.Add(this.myListView);
}

private void Button1_Click(System.Object sender, System.EventArgs e)
{

    // Use the ListView.TopItem property to access the SubItems
    // and then reset their appearance.
    myListView.TopItem.SubItems[1].ResetStyle();
    myListView.TopItem.SubItems[2].ResetStyle();
}

' Declare the Listview object.
Friend WithEvents myListView As System.Windows.Forms.ListView

' Initialize the ListView object with subitems of a different
' style than the default styles for the ListView.
Private Sub InitializeListView()

    ' Set the Location, View and Width properties for the 
    ' ListView object. 
    myListView = New ListView
    With (myListView)
        .Location = New System.Drawing.Point(20, 20)

        ' The View property must be set to Details for the 
        ' subitems to be visible.
        .View = View.Details
        .Width = 250
    End With

    ' Each SubItem object requires a column, so add three columns.
    Me.myListView.Columns.Add("Key", 50, HorizontalAlignment.Left)
    Me.myListView.Columns.Add("A", 100, HorizontalAlignment.Left)
    Me.myListView.Columns.Add("B", 100, HorizontalAlignment.Left)

    ' Add a ListItem object to the ListView.
    Dim entryListItem As ListViewItem = myListView.Items.Add("Items")

    ' Set UseItemStyleForSubItems property to false to change 
    ' look of subitems.
    entryListItem.UseItemStyleForSubItems = False

    ' Add the expense subitem.
    Dim expenseItem As ListViewItem.ListViewSubItem = _
        entryListItem.SubItems.Add("Expense")

    ' Change the expenseItem object's color and font.
    expenseItem.ForeColor = System.Drawing.Color.Red
    expenseItem.Font = New System.Drawing.Font _
        ("Arial", 10, System.Drawing.FontStyle.Italic)

    ' Add a subitem called revenueItem 
    Dim revenueItem As ListViewItem.ListViewSubItem = _
        entryListItem.SubItems.Add("Revenue")

    ' Change the revenueItem object's color and font.
    revenueItem.ForeColor = System.Drawing.Color.Blue
    revenueItem.Font = New System.Drawing.Font _
        ("Times New Roman", 10, System.Drawing.FontStyle.Bold)

    ' Add the ListView to the form.
    Me.Controls.Add(Me.myListView)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    ' Use the ListView.TopItem property to access the SubItems
    ' and then reset their appearance.
    myListView.TopItem.SubItems(1).ResetStyle()
    myListView.TopItem.SubItems(2).ResetStyle()
End Sub

설명

처음에는 인덱스 위치가 0인 항목이 컨트롤의 ListView 맨 위에 있습니다. ListView 컨트롤 내용이 스크롤되면 컨트롤 맨 위에 다른 항목이 있을 수 있습니다. 이 속성을 사용 하 여 표시 하거나 컨트롤의 맨 위에 표시 되는 항목을 확인할 수 있습니다 ListView . 원하는 상위 항목이 TopItem 목록 보기에 있는 위치에 따라 속성 값이 항상 유지되지는 않습니다.

언제든지 컨트롤에 ListView 표시되는 항목 수는 목록 보기의 높이와 포함된 항목의 크기에 따라 달라집니다. 항목이 목록 보기의 높이를 초과하면 항목은 사용자가 스크롤할 수 있는 여러 페이지로 계속 진행됩니다. 속성을 의 TopItem 마지막 페이지에 ListView있는 항목으로 설정하면 항목이 자동으로 보기로 스크롤되지만 마지막 TopItem 페이지의 실제 상위 항목으로 설정됩니다.

특정 항목이 컨트롤의 표시되는 영역에 있는지 확인하려면(반드시 맨 위 위치에 있는 것은 아님) 메서드를 EnsureVisible 사용합니다.

참고

속성 값false이 인 경우 Scrollable 이 속성을 설정해도 효과가 없습니다.

이 속성 설정은 버전 2.0 이전의 .NET Framework 버전에서 지원되지 않습니다.

적용 대상

추가 정보