ListView.ColumnHeaderCollection 클래스

정의

ListView 컨트롤의 열 머리글 컬렉션을 나타냅니다.

public: ref class ListView::ColumnHeaderCollection : System::Collections::IList
public class ListView.ColumnHeaderCollection : System.Collections.IList
[System.ComponentModel.ListBindable(false)]
public class ListView.ColumnHeaderCollection : System.Collections.IList
type ListView.ColumnHeaderCollection = class
    interface IList
    interface ICollection
    interface IEnumerable
[<System.ComponentModel.ListBindable(false)>]
type ListView.ColumnHeaderCollection = class
    interface IList
    interface ICollection
    interface IEnumerable
Public Class ListView.ColumnHeaderCollection
Implements IList
상속
ListView.ColumnHeaderCollection
특성
구현

예제

다음 코드 예제에서는 컨트롤의 열을 클릭할 때 항목을 수동으로 정렬 하는 컨트롤을 포함 ListView 하는 폼을 ListView 만듭니다. 이 예제에서는 비교를 수행하는 인터페이스를 System.Collections.IComparer 구현하는 라는 ListViewItemComparer 클래스를 ListViewItem 정의합니다. 이 예제에서는 의 instance ListViewItemComparer 만들고 이를 사용하여 컨트롤의 ListView 속성을 설정합니다ListViewItemSorter. 이벤트 처리기의 메서드 호출 ColumnClickSort 에 정의된 ListViewItemComparer 메서드를 사용하여 클릭한 열에 따라 항목의 종류를 수행합니다.

#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;
using namespace System::Collections;

// Implements the manual sorting of items by columns.
ref class ListViewItemComparer: public IComparer
{
private:
   int col;

public:
   ListViewItemComparer()
   {
      col = 0;
   }

   ListViewItemComparer( int column )
   {
      col = column;
   }

   virtual int Compare( Object^ x, Object^ y )
   {
      return String::Compare( (dynamic_cast<ListViewItem^>(x))->SubItems[ col ]->Text,
                              (dynamic_cast<ListViewItem^>(y))->SubItems[ col ]->Text );
   }
};

public ref class ListViewSortForm: public Form
{
private:
   ListView^ listView1;

public:
   ListViewSortForm()
   {
      // Create ListView items to add to the control.
      array<String^>^temp0 = {"Banana","a","b","c"};
      ListViewItem^ listViewItem1 = gcnew ListViewItem( temp0,-1,Color::Empty,Color::Yellow,nullptr );
      array<String^>^temp1 = {"Cherry","v","g","t"};
      ListViewItem^ listViewItem2 = gcnew ListViewItem( temp1,-1,Color::Empty,Color::Red,
                 gcnew System::Drawing::Font( "Microsoft Sans Serif",8.25F,FontStyle::Regular,GraphicsUnit::Point,0 ) );
      array<String^>^temp2 = {"Apple","h","j","n"};
      ListViewItem^ listViewItem3 = gcnew ListViewItem( temp2,-1,Color::Empty,Color::Lime,nullptr );
      array<String^>^temp3 = {"Pear","y","u","i"};
      ListViewItem^ listViewItem4 = gcnew ListViewItem( temp3,-1,Color::Empty,Color::FromArgb( 192, 128, 156 ),nullptr );

      //Initialize the ListView control and add columns to it.
      this->listView1 = gcnew ListView;

      // Set the initial sorting type for the ListView.
      this->listView1->Sorting = SortOrder::None;

      // Disable automatic sorting to enable manual sorting.
      this->listView1->View = View::Details;

      // Add columns and set their text.
      this->listView1->Columns->Add( gcnew ColumnHeader );
      this->listView1->Columns[ 0 ]->Text = "Column 1";
      this->listView1->Columns[ 0 ]->Width = 100;
      listView1->Columns->Add( gcnew ColumnHeader );
      listView1->Columns[ 1 ]->Text = "Column 2";
      listView1->Columns->Add( gcnew ColumnHeader );
      listView1->Columns[ 2 ]->Text = "Column 3";
      listView1->Columns->Add( gcnew ColumnHeader );
      listView1->Columns[ 3 ]->Text = "Column 4";

      // Suspend control logic until form is done configuring form.
      this->SuspendLayout();

      // Add Items to the ListView control.
      array<ListViewItem^>^temp4 = {listViewItem1,listViewItem2,listViewItem3,listViewItem4};
      this->listView1->Items->AddRange( temp4 );

      // Set the location and size of the ListView control.
      this->listView1->Location = Point(10,10);
      this->listView1->Name = "listView1";
      this->listView1->Size = System::Drawing::Size( 300, 100 );
      this->listView1->TabIndex = 0;

      // Enable editing of the items in the ListView.
      this->listView1->LabelEdit = true;

      // Connect the ListView::ColumnClick event to the ColumnClick event handler.
      this->listView1->ColumnClick += gcnew ColumnClickEventHandler( this, &ListViewSortForm::ColumnClick );

      // Initialize the form.
      this->ClientSize = System::Drawing::Size( 400, 400 );
      array<Control^>^temp5 = {this->listView1};
      this->Controls->AddRange( temp5 );
      this->Name = "ListViewSortForm";
      this->Text = "Sorted ListView Control";

      // Resume lay[Out] of* the form.
      this->ResumeLayout( false );
   }

private:

   // ColumnClick event handler.
   void ColumnClick( Object^ /*o*/, ColumnClickEventArgs^ e )
   {
      // Set the ListViewItemSorter property to a new ListViewItemComparer 
      // object. Setting this property immediately sorts the 
      // ListView using the ListViewItemComparer object.
      this->listView1->ListViewItemSorter = gcnew ListViewItemComparer( e->Column );
   }
};

[System::STAThreadAttribute]
int main()
{
   Application::Run( gcnew ListViewSortForm );
}
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Collections;

namespace ListViewSortFormNamespace
{

    public class ListViewSortForm : Form
    {
        private ListView listView1;
       
        public ListViewSortForm()
        {
            // Create ListView items to add to the control.
            ListViewItem listViewItem1 = new ListViewItem(new string[] {"Banana","a","b","c"}, -1, Color.Empty, Color.Yellow, null);
            ListViewItem listViewItem2 = new ListViewItem(new string[] {"Cherry","v","g","t"}, -1, Color.Empty, Color.Red, new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((System.Byte)(0))));
            ListViewItem listViewItem3 = new ListViewItem(new string[] {"Apple","h","j","n"}, -1, Color.Empty, Color.Lime, null);
            ListViewItem listViewItem4 = new ListViewItem(new string[] {"Pear","y","u","i"}, -1, Color.Empty, Color.FromArgb(((System.Byte)(192)), ((System.Byte)(128)), ((System.Byte)(156))), null);
     
            //Initialize the ListView control and add columns to it.
            this.listView1 = new ListView();

            // Set the initial sorting type for the ListView.
            this.listView1.Sorting = SortOrder.None;
            // Disable automatic sorting to enable manual sorting.
            this.listView1.View = View.Details;
            // Add columns and set their text.
            this.listView1.Columns.Add(new ColumnHeader());
            this.listView1.Columns[0].Text = "Column 1";
            this.listView1.Columns[0].Width = 100;
            listView1.Columns.Add(new ColumnHeader());
            listView1.Columns[1].Text = "Column 2";
            listView1.Columns.Add(new ColumnHeader());
            listView1.Columns[2].Text = "Column 3";
            listView1.Columns.Add(new ColumnHeader());
            listView1.Columns[3].Text = "Column 4";
            // Suspend control logic until form is done configuring form.
            this.SuspendLayout();
            // Add Items to the ListView control.
            this.listView1.Items.AddRange(new ListViewItem[] {listViewItem1,
                listViewItem2,
                listViewItem3,
                listViewItem4});
            // Set the location and size of the ListView control.
            this.listView1.Location = new Point(10, 10);
            this.listView1.Name = "listView1";
            this.listView1.Size = new Size(300, 100);
            this.listView1.TabIndex = 0;
            // Enable editing of the items in the ListView.
            this.listView1.LabelEdit = true;
            // Connect the ListView.ColumnClick event to the ColumnClick event handler.
            this.listView1.ColumnClick += new ColumnClickEventHandler(ColumnClick);
            
            // Initialize the form.
            this.ClientSize = new Size(400, 400);
            this.Controls.AddRange(new Control[] {this.listView1});
            this.Name = "ListViewSortForm";
            this.Text = "Sorted ListView Control";
            // Resume layout of the form.
            this.ResumeLayout(false);
        }

        // ColumnClick event handler.
        private void ColumnClick(object o, ColumnClickEventArgs e)
        {
            // Set the ListViewItemSorter property to a new ListViewItemComparer 
            // object. Setting this property immediately sorts the 
            // ListView using the ListViewItemComparer object.
            this.listView1.ListViewItemSorter = new ListViewItemComparer(e.Column);
        }

        [System.STAThreadAttribute()]
        public static void Main()
        {
            Application.Run(new ListViewSortForm());
        }
    }

    // Implements the manual sorting of items by columns.
    class ListViewItemComparer : IComparer
    {
        private int col;
        public ListViewItemComparer()
        {
            col = 0;
        }
        public ListViewItemComparer(int column)
        {
            col = column;
        }
        public int Compare(object x, object y)
        {
            return String.Compare(((ListViewItem)x).SubItems[col].Text, ((ListViewItem)y).SubItems[col].Text);
        }
    }
}
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Collections


Namespace ListViewSortFormNamespace

    Public Class ListViewSortForm
        Inherits Form

        Private listView1 As ListView

        Public Sub New()
            ' Create ListView items to add to the control.
            Dim listViewItem1 As New ListViewItem(New String() {"Banana", "a", "b", "c"}, -1, Color.Empty, Color.Yellow, Nothing)
            Dim listViewItem2 As New ListViewItem(New String() {"Cherry", "v", "g", "t"}, -1, Color.Empty, Color.Red, New Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point, CType(0, System.Byte)))
            Dim listViewItem3 As New ListViewItem(New String() {"Apple", "h", "j", "n"}, -1, Color.Empty, Color.Lime, Nothing)
            Dim listViewItem4 As New ListViewItem(New String() {"Pear", "y", "u", "i"}, -1, Color.Empty, Color.FromArgb(CType(192, System.Byte), CType(128, System.Byte), CType(156, System.Byte)), Nothing)

            'Initialize the ListView control and add columns to it.
            Me.listView1 = New ListView

            ' Set the initial sorting type for the ListView.
            Me.listView1.Sorting = SortOrder.None
            ' Disable automatic sorting to enable manual sorting.
            Me.listView1.View = View.Details
            ' Add columns and set their text.
            Me.listView1.Columns.Add(New ColumnHeader)
            Me.listView1.Columns(0).Text = "Column 1"
            Me.listView1.Columns(0).Width = 100
            listView1.Columns.Add(New ColumnHeader)
            listView1.Columns(1).Text = "Column 2"
            listView1.Columns.Add(New ColumnHeader)
            listView1.Columns(2).Text = "Column 3"
            listView1.Columns.Add(New ColumnHeader)
            listView1.Columns(3).Text = "Column 4"
            ' Suspend control logic until form is done configuring form.
            Me.SuspendLayout()
            ' Add Items to the ListView control.
            Me.listView1.Items.AddRange(New ListViewItem() {listViewItem1, listViewItem2, listViewItem3, listViewItem4})
            ' Set the location and size of the ListView control.
            Me.listView1.Location = New Point(10, 10)
            Me.listView1.Name = "listView1"
            Me.listView1.Size = New Size(300, 100)
            Me.listView1.TabIndex = 0
            ' Enable editing of the items in the ListView.
            Me.listView1.LabelEdit = True
            ' Connect the ListView.ColumnClick event to the ColumnClick event handler.
            AddHandler Me.listView1.ColumnClick, AddressOf ColumnClick

            ' Initialize the form.
            Me.ClientSize = New Size(400, 400)
            Me.Controls.AddRange(New Control() {Me.listView1})
            Me.Name = "ListViewSortForm"
            Me.Text = "Sorted ListView Control"
            ' Resume layout of the form.
            Me.ResumeLayout(False)
        End Sub


        ' ColumnClick event handler.
        Private Sub ColumnClick(ByVal o As Object, ByVal e As ColumnClickEventArgs)
            ' Set the ListViewItemSorter property to a new ListViewItemComparer 
            ' object. Setting this property immediately sorts the 
            ' ListView using the ListViewItemComparer object.
            Me.listView1.ListViewItemSorter = New ListViewItemComparer(e.Column)
        End Sub

    End Class

    ' Implements the manual sorting of items by columns.
    Class ListViewItemComparer
        Implements IComparer

        Private col As Integer

        Public Sub New()
            col = 0
        End Sub

        Public Sub New(ByVal column As Integer)
            col = column
        End Sub

        Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer _
           Implements IComparer.Compare
            Return [String].Compare(CType(x, ListViewItem).SubItems(col).Text, CType(y, ListViewItem).SubItems(col).Text)
        End Function
    End Class
End Namespace

설명

ListView.ColumnHeaderCollection 클래스는 속성이 로 설정된 Details경우 View 컨트롤에 ListView 표시되는 열 머리글을 저장합니다. 는 ListView.ColumnHeaderCollection 열에 대해 표시할 텍스트와 열을 표시할 때 컨트롤에 ListView 열 머리글이 표시되는 방식을 정의하는 개체를 저장 ColumnHeader 합니다. 가 ListView 열을 표시하면 항목 및 해당 하위 항목이 해당 열에 표시됩니다. 아래에 표시되는 열 하위 항목 데이터를 지정하려면 클래스를 ListViewItem.ListViewSubItemCollection 참조하세요.

컬렉션에 열 머리글을 추가하는 방법에는 여러 가지가 있습니다. 메서드는 Add 컬렉션에 단일 열 헤더를 추가합니다. 컬렉션에 여러 열 머리글을 추가하려면 개체 배열 ColumnHeader 을 만들어 메서드에 AddRange 전달합니다. 컬렉션의 특정 위치에 열 머리글을 삽입하려는 경우 메서드를 Insert 사용할 수 있습니다. 열 머리글을 제거하려면 컬렉션에서 열 머리글이 RemoveRemoveAt 있는 위치를 알고 있는 경우 메서드 또는 메서드를 사용할 수 있습니다. Clear 메서드를 사용하면 메서드를 사용하여 Remove 한 번에 하나의 열 머리글을 제거하는 대신 컬렉션에서 모든 열 머리글을 제거할 수 있습니다.

는 열 머리글을 ListView.ColumnHeaderCollection 추가 및 제거하기 위한 메서드 및 속성 외에도 컬렉션에서 열 머리글을 찾는 메서드를 제공합니다. Contains 메서드를 사용하면 열 머리글이 컬렉션의 멤버인지 여부를 확인할 수 있습니다. 열 머리글이 컬렉션에 있다는 것을 알게 되면 메서드를 IndexOf 사용하여 열 머리글이 컬렉션에 있는 위치를 확인할 수 있습니다.

참고

모든 열의 결합된 너비가 32,768픽셀을 초과하면 예기치 않은 동작이 발생할 수 있습니다.

생성자

ListView.ColumnHeaderCollection(ListView)

ListView.ColumnHeaderCollection 클래스의 새 인스턴스를 초기화합니다.

속성

Count

컬렉션의 항목 수를 가져옵니다.

IsReadOnly

컬렉션이 읽기 전용인지를 나타내는 값을 가져옵니다.

Item[Int32]

컬렉션의 지정된 인덱스에 있는 열 머리글을 가져옵니다.

Item[String]

컬렉션에서 지정된 키를 가진 열 머리글을 가져옵니다.

메서드

Add(ColumnHeader)

기존 ColumnHeader을 컬렉션에 추가합니다.

Add(String)

지정된 텍스트를 가진 열을 만든 다음 컬렉션에 추가합니다.

Add(String, Int32)

지정된 텍스트와 너비를 갖는 열을 만든 다음 컬렉션에 추가합니다.

Add(String, Int32, HorizontalAlignment)

지정한 텍스트, 너비, 정렬 설정으로 열 머리글을 컬렉션에 추가합니다.

Add(String, String)

지정된 텍스트와 키를 갖는 열을 만든 다음 컬렉션에 추가합니다.

Add(String, String, Int32)

지정된 텍스트, 키 및 너비를 갖는 열을 만든 다음 컬렉션에 추가합니다.

Add(String, String, Int32, HorizontalAlignment, Int32)

지정된 키, 맞춤 텍스트, 너비 및 이미지 인덱스를 갖는 열을 만든 다음 컬렉션에 추가합니다.

Add(String, String, Int32, HorizontalAlignment, String)

지정된 키, 맞춤 텍스트, 너비 및 이미지 키를 갖는 열을 만든 다음 컬렉션에 추가합니다.

AddRange(ColumnHeader[])

열 머리글 배열을 컬렉션에 추가합니다.

Clear()

컬렉션에서 모든 열 머리글을 제거합니다.

Contains(ColumnHeader)

지정된 열 머리글이 컬렉션에 있는지 여부를 확인합니다.

ContainsKey(String)

지정된 키를 가진 열이 컬렉션에 있는지 여부를 확인합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetEnumerator()

열 머리글 컬렉션을 반복하는 데 사용할 열거자를 반환합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IndexOf(ColumnHeader)

컬렉션 내에서 지정된 열 머리글의 인덱스를 반환합니다.

IndexOfKey(String)

지정된 키를 갖는 열의 인덱스를 확인합니다.

Insert(Int32, ColumnHeader)

지정한 인덱스로 기존 열 머리글을 컬렉션에 삽입합니다.

Insert(Int32, String)

지정된 텍스트를 가진 열 머리글을 새로 만들어 컬렉션의 지정된 인덱스에 삽입합니다.

Insert(Int32, String, Int32)

지정된 텍스트 및 초기 너비를 가진 열 머리글을 새로 만들어 컬렉션의 지정된 인덱스에 삽입합니다.

Insert(Int32, String, Int32, HorizontalAlignment)

새 열 머리글을 만들어 컬렉션의 지정한 위치에 삽입합니다.

Insert(Int32, String, String)

지정된 텍스트 및 키를 가진 열 머리글을 새로 만들어 컬렉션의 지정된 인덱스에 삽입합니다.

Insert(Int32, String, String, Int32)

지정된 텍스트, 키 및 너비를 가진 열 머리글을 새로 만들어 컬렉션의 지정된 인덱스에 삽입합니다.

Insert(Int32, String, String, Int32, HorizontalAlignment, Int32)

지정된 맞춤 텍스트, 키, 너비 및 이미지 인덱스를 가진 열 머리글을 새로 만들어 컬렉션의 지정된 인덱스에 삽입합니다.

Insert(Int32, String, String, Int32, HorizontalAlignment, String)

지정된 맞춤 텍스트, 키, 너비 및 이미지 키를 가진 열 머리글을 새로 만들어 컬렉션의 지정된 인덱스에 삽입합니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
Remove(ColumnHeader)

컬렉션에서 지정한 열 머리글을 제거합니다.

RemoveAt(Int32)

컬렉션의 지정된 인덱스에서 열 머리글을 제거합니다.

RemoveByKey(String)

컬렉션에서 지정된 키를 가진 열을 제거합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

ICollection.CopyTo(Array, Int32)

ColumnHeaderListView.ColumnHeaderCollection 개체를 배열의 특정 배열 인덱스부터 시작하는 위치에 복사합니다.

ICollection.IsSynchronized

ListView.ColumnHeaderCollection에 대한 액세스가 동기화되어 스레드로부터 안전하게 보호되는지를 나타내는 값을 가져옵니다.

ICollection.SyncRoot

컨트롤 컬렉션에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다.

IList.Add(Object)

ColumnHeaderListView를 추가합니다.

IList.Contains(Object)

지정된 열 머리글이 컬렉션에 있는지 여부를 확인합니다.

IList.IndexOf(Object)

이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다.

컬렉션 내에서 지정된 열 머리글의 인덱스를 반환합니다.

IList.Insert(Int32, Object)

지정한 인덱스로 기존 열 머리글을 컬렉션에 삽입합니다.

IList.IsFixedSize

ListView.ColumnHeaderCollection의 크기가 고정되어 있는지 여부를 나타내는 값을 가져옵니다.

IList.Item[Int32]

컬렉션에서 지정한 인덱스의 열 머리글을 가져오거나 설정합니다.

IList.Remove(Object)

컬렉션에서 지정한 열 머리글을 제거합니다.

확장 메서드

Cast<TResult>(IEnumerable)

IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.

OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.

AsParallel(IEnumerable)

쿼리를 병렬화할 수 있도록 합니다.

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상