ListView.ColumnHeaderCollection.Add 메서드

정의

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

오버로드

Add(String)

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

Add(ColumnHeader)

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

Add(String, Int32)

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

Add(String, String)

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

Add(String, String, Int32)

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

Add(String, Int32, HorizontalAlignment)

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

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

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

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

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

Add(String)

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

public:
 virtual System::Windows::Forms::ColumnHeader ^ Add(System::String ^ text);
public virtual System.Windows.Forms.ColumnHeader Add (string text);
public virtual System.Windows.Forms.ColumnHeader Add (string? text);
abstract member Add : string -> System.Windows.Forms.ColumnHeader
override this.Add : string -> System.Windows.Forms.ColumnHeader
Public Overridable Function Add (text As String) As ColumnHeader

매개 변수

text
String

열 머리글에 표시되는 텍스트입니다.

반환

지정된 텍스트를 가지며 ColumnHeader에 추가된 ListView.ColumnHeaderCollection입니다.

설명

열 머리글이 컬렉션의 끝에 추가됩니다.

적용 대상

Add(ColumnHeader)

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

public:
 virtual int Add(System::Windows::Forms::ColumnHeader ^ value);
public virtual int Add (System.Windows.Forms.ColumnHeader value);
abstract member Add : System.Windows.Forms.ColumnHeader -> int
override this.Add : System.Windows.Forms.ColumnHeader -> int
Public Overridable Function Add (value As ColumnHeader) As Integer

매개 변수

value
ColumnHeader

컬렉션에 추가할 ColumnHeader입니다.

반환

항목이 추가된 컬렉션의 인덱스(0부터 시작)입니다.

예제

다음 코드 예제에서는 컨트롤의 열을 클릭할 때 항목을 수동으로 정렬 하는 컨트롤을 포함 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

설명

이 버전을 사용할 수는 Add 메서드는 기존 항목 추가를 ColumnHeader 컬렉션에 있습니다. 컬렉션에 추가할 때 새 ColumnHeader 를 만들려면 다른 버전의 메서드를 Add 사용할 수 있습니다.

열 머리글이 추가되면 컬렉션의 끝에 추가됩니다. 특정 위치의 컬렉션에 열 머리글을 삽입하려면 메서드를 Insert 사용합니다. 단일 작업에서 컬렉션에 열 머리글 집합을 추가하려면 메서드를 AddRange 사용합니다.

추가 정보

적용 대상

Add(String, Int32)

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

public:
 virtual System::Windows::Forms::ColumnHeader ^ Add(System::String ^ text, int width);
public virtual System.Windows.Forms.ColumnHeader Add (string text, int width);
public virtual System.Windows.Forms.ColumnHeader Add (string? text, int width);
abstract member Add : string * int -> System.Windows.Forms.ColumnHeader
override this.Add : string * int -> System.Windows.Forms.ColumnHeader
Public Overridable Function Add (text As String, width As Integer) As ColumnHeader

매개 변수

text
String

컬렉션에 추가할 ColumnHeader의 텍스트입니다.

width
Int32

컬렉션에 추가할 ColumnHeader의 너비입니다.

반환

지정된 텍스트 및 너비를 가지며 ColumnHeader에 추가된 ListView.ColumnHeaderCollection입니다.

설명

열은 컬렉션의 끝에 추가됩니다.

적용 대상

Add(String, String)

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

public:
 virtual System::Windows::Forms::ColumnHeader ^ Add(System::String ^ key, System::String ^ text);
public virtual System.Windows.Forms.ColumnHeader Add (string key, string text);
abstract member Add : string * string -> System.Windows.Forms.ColumnHeader
override this.Add : string * string -> System.Windows.Forms.ColumnHeader
Public Overridable Function Add (key As String, text As String) As ColumnHeader

매개 변수

key
String

컬렉션에 추가할 ColumnHeader의 키입니다.

text
String

컬렉션에 추가할 ColumnHeader의 텍스트입니다.

반환

지정된 키 및 텍스트를 가지며 ColumnHeader에 추가된 ListView.ColumnHeaderCollection입니다.

설명

속성은 Name 의 열에 대한 키에 ListView.ColumnHeaderCollection해당합니다.

열은 컬렉션의 끝에 추가됩니다.

적용 대상

Add(String, String, Int32)

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

public:
 virtual System::Windows::Forms::ColumnHeader ^ Add(System::String ^ key, System::String ^ text, int width);
public virtual System.Windows.Forms.ColumnHeader Add (string key, string text, int width);
abstract member Add : string * string * int -> System.Windows.Forms.ColumnHeader
override this.Add : string * string * int -> System.Windows.Forms.ColumnHeader
Public Overridable Function Add (key As String, text As String, width As Integer) As ColumnHeader

매개 변수

key
String

열 머리글의 키입니다.

text
String

열 머리글에 표시되는 텍스트입니다.

width
Int32

ColumnHeader의 초기 너비입니다.

반환

지정된 텍스트, 키 및 너비를 가지며 컬렉션에 추가된 ColumnHeader입니다.

설명

속성은 Name 의 열에 대한 키에 ListView.ColumnHeaderCollection해당합니다.

열은 컬렉션의 끝에 추가됩니다.

적용 대상

Add(String, Int32, HorizontalAlignment)

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

public:
 virtual System::Windows::Forms::ColumnHeader ^ Add(System::String ^ str, int width, System::Windows::Forms::HorizontalAlignment textAlign);
public:
 virtual System::Windows::Forms::ColumnHeader ^ Add(System::String ^ text, int width, System::Windows::Forms::HorizontalAlignment textAlign);
public virtual System.Windows.Forms.ColumnHeader Add (string str, int width, System.Windows.Forms.HorizontalAlignment textAlign);
public virtual System.Windows.Forms.ColumnHeader Add (string text, int width, System.Windows.Forms.HorizontalAlignment textAlign);
public virtual System.Windows.Forms.ColumnHeader Add (string? text, int width, System.Windows.Forms.HorizontalAlignment textAlign);
abstract member Add : string * int * System.Windows.Forms.HorizontalAlignment -> System.Windows.Forms.ColumnHeader
override this.Add : string * int * System.Windows.Forms.HorizontalAlignment -> System.Windows.Forms.ColumnHeader
abstract member Add : string * int * System.Windows.Forms.HorizontalAlignment -> System.Windows.Forms.ColumnHeader
override this.Add : string * int * System.Windows.Forms.HorizontalAlignment -> System.Windows.Forms.ColumnHeader
Public Overridable Function Add (str As String, width As Integer, textAlign As HorizontalAlignment) As ColumnHeader
Public Overridable Function Add (text As String, width As Integer, textAlign As HorizontalAlignment) As ColumnHeader

매개 변수

strtext
String

열 머리글에 표시되는 텍스트입니다.

width
Int32

열 머리글의 초기 너비입니다.

textAlign
HorizontalAlignment

HorizontalAlignment 값 중 하나입니다.

반환

생성되어 컬렉션에 추가된 ColumnHeader입니다.

예제

다음 코드 예제를 ListView 3 개를 사용 하 여 컨트롤 ListViewItem 지정 된 개체 및 3 ListViewItem.ListViewSubItem 각 항목에 대해 지정 된 개체입니다. 예제에서는 ColumnHeader 하위 항목 세부 정보 보기에 표시할 개체입니다. 두 개의 ImageList 이미지를 제공 하 여 코드 예제의 만들어집니다 개체는 ListViewItem 개체입니다. 이러한 ImageList 개체에 추가 되는 LargeImageListSmallImageList 속성입니다. 이 예제에서는 만들기에서 다음 속성을 사용 합니다 ListView 제어:

이 예제 코드를 추가 하려면를 Form 폼에서 다른 메서드나 생성자의 예제에서 만든 메서드를 호출 합니다. 이 예제에서는 명명 된 이미지도 필요 MySmallImage1, MySmallImage2MyLargeImage1, 및 MyLargeImage2 C 드라이브의 루트 디렉터리에 있는

private:
   void CreateMyListView()
   {
      // Create a new ListView control.
      ListView^ listView1 = gcnew ListView;
      listView1->Bounds = Rectangle(Point(10,10),System::Drawing::Size( 300, 200 ));

      // Set the view to show details.
      listView1->View = View::Details;

      // Allow the user to edit item text.
      listView1->LabelEdit = true;

      // Allow the user to rearrange columns.
      listView1->AllowColumnReorder = true;

      // Display check boxes.
      listView1->CheckBoxes = true;

      // Select the item and subitems when selection is made.
      listView1->FullRowSelect = true;

      // Display grid lines.
      listView1->GridLines = true;

      // Sort the items in the list in ascending order.
      listView1->Sorting = SortOrder::Ascending;

      // Create three items and three sets of subitems for each item.
      ListViewItem^ item1 = gcnew ListViewItem( "item1",0 );

      // Place a check mark next to the item.
      item1->Checked = true;
      item1->SubItems->Add( "1" );
      item1->SubItems->Add( "2" );
      item1->SubItems->Add( "3" );
      ListViewItem^ item2 = gcnew ListViewItem( "item2",1 );
      item2->SubItems->Add( "4" );
      item2->SubItems->Add( "5" );
      item2->SubItems->Add( "6" );
      ListViewItem^ item3 = gcnew ListViewItem( "item3",0 );

      // Place a check mark next to the item.
      item3->Checked = true;
      item3->SubItems->Add( "7" );
      item3->SubItems->Add( "8" );
      item3->SubItems->Add( "9" );

      // Create columns for the items and subitems.
      // Width of -2 indicates auto-size.
      listView1->Columns->Add( "Item Column", -2, HorizontalAlignment::Left );
      listView1->Columns->Add( "Column 2", -2, HorizontalAlignment::Left );
      listView1->Columns->Add( "Column 3", -2, HorizontalAlignment::Left );
      listView1->Columns->Add( "Column 4", -2, HorizontalAlignment::Center );

      //Add the items to the ListView.
      array<ListViewItem^>^temp1 = {item1,item2,item3};
      listView1->Items->AddRange( temp1 );

      // Create two ImageList objects.
      ImageList^ imageListSmall = gcnew ImageList;
      ImageList^ imageListLarge = gcnew ImageList;

      // Initialize the ImageList objects with bitmaps.
      imageListSmall->Images->Add( Bitmap::FromFile( "C:\\MySmallImage1.bmp" ) );
      imageListSmall->Images->Add( Bitmap::FromFile( "C:\\MySmallImage2.bmp" ) );
      imageListLarge->Images->Add( Bitmap::FromFile( "C:\\MyLargeImage1.bmp" ) );
      imageListLarge->Images->Add( Bitmap::FromFile( "C:\\MyLargeImage2.bmp" ) );

      //Assign the ImageList objects to the ListView.
      listView1->LargeImageList = imageListLarge;
      listView1->SmallImageList = imageListSmall;
      
      // Add the ListView to the control collection.
      this->Controls->Add( listView1 );
   }
private void CreateMyListView()
{
    // Create a new ListView control.
    ListView listView1 = new ListView();
    listView1.Bounds = new Rectangle(new Point(10,10), new Size(300,200));

    // Set the view to show details.
    listView1.View = View.Details;
    // Allow the user to edit item text.
    listView1.LabelEdit = true;
    // Allow the user to rearrange columns.
    listView1.AllowColumnReorder = true;
    // Display check boxes.
    listView1.CheckBoxes = true;
    // Select the item and subitems when selection is made.
    listView1.FullRowSelect = true;
    // Display grid lines.
    listView1.GridLines = true;
    // Sort the items in the list in ascending order.
    listView1.Sorting = SortOrder.Ascending;
                
    // Create three items and three sets of subitems for each item.
    ListViewItem item1 = new ListViewItem("item1",0);
    // Place a check mark next to the item.
    item1.Checked = true;
    item1.SubItems.Add("1");
    item1.SubItems.Add("2");
    item1.SubItems.Add("3");
    ListViewItem item2 = new ListViewItem("item2",1);
    item2.SubItems.Add("4");
    item2.SubItems.Add("5");
    item2.SubItems.Add("6");
    ListViewItem item3 = new ListViewItem("item3",0);
    // Place a check mark next to the item.
    item3.Checked = true;
    item3.SubItems.Add("7");
    item3.SubItems.Add("8");
    item3.SubItems.Add("9");

    // Create columns for the items and subitems.
    // Width of -2 indicates auto-size.
    listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left);
    listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left);
    listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left);
    listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center);

    //Add the items to the ListView.
    listView1.Items.AddRange(new ListViewItem[]{item1,item2,item3});

    // Create two ImageList objects.
    ImageList imageListSmall = new ImageList();
    ImageList imageListLarge = new ImageList();

    // Initialize the ImageList objects with bitmaps.
    imageListSmall.Images.Add(Bitmap.FromFile("C:\\MySmallImage1.bmp"));
    imageListSmall.Images.Add(Bitmap.FromFile("C:\\MySmallImage2.bmp"));
    imageListLarge.Images.Add(Bitmap.FromFile("C:\\MyLargeImage1.bmp"));
    imageListLarge.Images.Add(Bitmap.FromFile("C:\\MyLargeImage2.bmp"));

    //Assign the ImageList objects to the ListView.
    listView1.LargeImageList = imageListLarge;
    listView1.SmallImageList = imageListSmall;

    // Add the ListView to the control collection.
    this.Controls.Add(listView1);
}
Private Sub CreateMyListView()
    ' Create a new ListView control.
    Dim listView1 As New ListView()
    listView1.Bounds = New Rectangle(New Point(10, 10), New Size(300, 200))

    ' Set the view to show details.
    listView1.View = View.Details
    ' Allow the user to edit item text.
    listView1.LabelEdit = True
    ' Allow the user to rearrange columns.
    listView1.AllowColumnReorder = True
    ' Display check boxes.
    listView1.CheckBoxes = True
    ' Select the item and subitems when selection is made.
    listView1.FullRowSelect = True
    ' Display grid lines.
    listView1.GridLines = True
    ' Sort the items in the list in ascending order.
    listView1.Sorting = SortOrder.Ascending

    ' Create three items and three sets of subitems for each item.
    Dim item1 As New ListViewItem("item1", 0)
    ' Place a check mark next to the item.
    item1.Checked = True
    item1.SubItems.Add("1")
    item1.SubItems.Add("2")
    item1.SubItems.Add("3")
    Dim item2 As New ListViewItem("item2", 1)
    item2.SubItems.Add("4")
    item2.SubItems.Add("5")
    item2.SubItems.Add("6")
    Dim item3 As New ListViewItem("item3", 0)
    ' Place a check mark next to the item.
    item3.Checked = True
    item3.SubItems.Add("7")
    item3.SubItems.Add("8")
    item3.SubItems.Add("9")

    ' Create columns for the items and subitems.
    ' Width of -2 indicates auto-size.
    listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
    listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
    listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
    listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

    'Add the items to the ListView.
    listView1.Items.AddRange(New ListViewItem() {item1, item2, item3})

    ' Create two ImageList objects.
    Dim imageListSmall As New ImageList()
    Dim imageListLarge As New ImageList()

    ' Initialize the ImageList objects with bitmaps.
    imageListSmall.Images.Add(Bitmap.FromFile("C:\MySmallImage1.bmp"))
    imageListSmall.Images.Add(Bitmap.FromFile("C:\MySmallImage2.bmp"))
    imageListLarge.Images.Add(Bitmap.FromFile("C:\MyLargeImage1.bmp"))
    imageListLarge.Images.Add(Bitmap.FromFile("C:\MyLargeImage2.bmp"))

    'Assign the ImageList objects to the ListView.
    listView1.LargeImageList = imageListLarge
    listView1.SmallImageList = imageListSmall

    ' Add the ListView to the control collection.
    Me.Controls.Add(listView1)
End Sub

설명

이 버전의 메서드를 사용하여 컬렉션에 Add 추가할 새 ColumnHeader 를 만들 수 있습니다. 컨트롤에 추가된 새 ColumnHeader 의 텍스트는 매개 변수를 기반으로 합니다 text . 또한 이 버전의 Add 메서드를 사용하면 열의 너비와 열 머리글의 텍스트 맞춤을 지정할 수 있습니다. 컬렉션에 추가하려는 기존 ColumnHeader 가 있는 경우 을 해당 매개 변수로 허용하는 ColumnHeader 메서드의 Add 버전을 사용합니다.

열 머리글이 추가되면 컬렉션의 끝에 추가됩니다. 특정 위치의 컬렉션에 열 머리글을 삽입하려면 메서드를 Insert 사용합니다. 단일 작업에서 컬렉션에 열 머리글 집합을 추가하려면 메서드를 AddRange 사용합니다.

추가 정보

적용 대상

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

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

public:
 virtual System::Windows::Forms::ColumnHeader ^ Add(System::String ^ key, System::String ^ text, int width, System::Windows::Forms::HorizontalAlignment textAlign, int imageIndex);
public virtual System.Windows.Forms.ColumnHeader Add (string key, string text, int width, System.Windows.Forms.HorizontalAlignment textAlign, int imageIndex);
abstract member Add : string * string * int * System.Windows.Forms.HorizontalAlignment * int -> System.Windows.Forms.ColumnHeader
override this.Add : string * string * int * System.Windows.Forms.HorizontalAlignment * int -> System.Windows.Forms.ColumnHeader
Public Overridable Function Add (key As String, text As String, width As Integer, textAlign As HorizontalAlignment, imageIndex As Integer) As ColumnHeader

매개 변수

key
String

열 머리글의 키입니다.

text
String

열 머리글에 표시되는 텍스트입니다.

width
Int32

열 머리글의 초기 너비입니다.

textAlign
HorizontalAlignment

HorizontalAlignment 값 중 하나입니다.

imageIndex
Int32

컬렉션에 표시할 이미지의 인덱스 값입니다.

반환

지정된 키, 맞춤 텍스트, 너비 및 이미지 인덱스를 가지며 컬렉션에 추가된 ColumnHeader입니다.

설명

속성은 Name 의 열에 대한 키에 ListView.ColumnHeaderCollection해당합니다.

열은 컬렉션의 끝에 추가됩니다.

적용 대상

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

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

public:
 virtual System::Windows::Forms::ColumnHeader ^ Add(System::String ^ key, System::String ^ text, int width, System::Windows::Forms::HorizontalAlignment textAlign, System::String ^ imageKey);
public virtual System.Windows.Forms.ColumnHeader Add (string key, string text, int width, System.Windows.Forms.HorizontalAlignment textAlign, string imageKey);
public virtual System.Windows.Forms.ColumnHeader Add (string? key, string? text, int width, System.Windows.Forms.HorizontalAlignment textAlign, string imageKey);
abstract member Add : string * string * int * System.Windows.Forms.HorizontalAlignment * string -> System.Windows.Forms.ColumnHeader
override this.Add : string * string * int * System.Windows.Forms.HorizontalAlignment * string -> System.Windows.Forms.ColumnHeader
Public Overridable Function Add (key As String, text As String, width As Integer, textAlign As HorizontalAlignment, imageKey As String) As ColumnHeader

매개 변수

key
String

열 머리글의 키입니다.

text
String

열 머리글에 표시되는 텍스트입니다.

width
Int32

열 머리글의 초기 너비입니다.

textAlign
HorizontalAlignment

HorizontalAlignment 값 중 하나입니다.

imageKey
String

열 머리글에 표시할 이미지의 키 값입니다.

반환

지정된 키, 맞춤 텍스트, 너비 및 이미지 키를 가지며 컬렉션에 추가된 ColumnHeader입니다.

설명

속성은 Name 의 열에 대한 키에 ListView.ColumnHeaderCollection해당합니다.

열은 컬렉션의 끝에 추가됩니다.

적용 대상