ColumnHeader 类

定义

ListView 控件中显示一个列标题。

public ref class ColumnHeader : System::ComponentModel::Component, ICloneable
public class ColumnHeader : System.ComponentModel.Component, ICloneable
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ColumnHeaderConverter))]
public class ColumnHeader : System.ComponentModel.Component, ICloneable
type ColumnHeader = class
    inherit Component
    interface ICloneable
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ColumnHeaderConverter))>]
type ColumnHeader = class
    inherit Component
    interface ICloneable
Public Class ColumnHeader
Inherits Component
Implements ICloneable
继承
属性
实现

示例

下面的代码示例演示如何初始化 ListView 控件。 该示例创建 ColumnHeader 对象并设置列标题的 TextTextAlignWidth 属性。 该示例还将项和子项添加到 ListView。 若要运行此示例,请将以下代码粘贴到窗体中,并从窗体的构造函数或Load事件处理程序调用 PopulateListView 方法。

private:
   void PopulateListView()
   {
      ListView1->Width = 270;
      ListView1->Location = System::Drawing::Point( 10, 10 );
      
      // Declare and construct the ColumnHeader objects.
      ColumnHeader^ header1;
      ColumnHeader^ header2;
      header1 = gcnew ColumnHeader;
      header2 = gcnew ColumnHeader;
      
      // Set the text, alignment and width for each column header.
      header1->Text = "File name";
      header1->TextAlign = HorizontalAlignment::Left;
      header1->Width = 70;
      header2->TextAlign = HorizontalAlignment::Left;
      header2->Text = "Location";
      header2->Width = 200;
      
      // Add the headers to the ListView control.
      ListView1->Columns->Add( header1 );
      ListView1->Columns->Add( header2 );
            
      // Specify that each item appears on a separate line.
      ListView1->View = View::Details;

      // Populate the ListView.Items property.
      // Set the directory to the sample picture directory.
      System::IO::DirectoryInfo^ dirInfo = gcnew System::IO::DirectoryInfo( "C:\\Documents and Settings\\All Users"
      "\\Documents\\My Pictures\\Sample Pictures" );
      
      // Get the .jpg files from the directory
      array<System::IO::FileInfo^>^files = dirInfo->GetFiles( "*.jpg" );
      
      // Add each file name and full name including path
      // to the ListView.
      if ( files != nullptr )
      {
         System::Collections::IEnumerator^ myEnum = files->GetEnumerator();
         while ( myEnum->MoveNext() )
         {
            System::IO::FileInfo^ file = safe_cast<System::IO::FileInfo^>(myEnum->Current);
            ListViewItem^ item = gcnew ListViewItem( file->Name );
            item->SubItems->Add( file->FullName );
            ListView1->Items->Add( item );
         }
      }
   }
private void PopulateListView()
{
    ListView1.Width = 270;
    ListView1.Location = new System.Drawing.Point(10, 10);

    // Declare and construct the ColumnHeader objects.
    ColumnHeader header1, header2;
    header1 = new ColumnHeader();
    header2 = new ColumnHeader();

    // Set the text, alignment and width for each column header.
    header1.Text = "File name";
    header1.TextAlign = HorizontalAlignment.Left;
    header1.Width = 70;

    header2.TextAlign = HorizontalAlignment.Left;
    header2.Text = "Location";
    header2.Width = 200;

    // Add the headers to the ListView control.
    ListView1.Columns.Add(header1);
    ListView1.Columns.Add(header2);

    // Specify that each item appears on a separate line.
    ListView1.View = View.Details;
    
    // Populate the ListView.Items property.
    // Set the directory to the sample picture directory.
    System.IO.DirectoryInfo dirInfo = 
        new System.IO.DirectoryInfo(
        "C:\\Documents and Settings\\All Users" +
        "\\Documents\\My Pictures\\Sample Pictures");

    // Get the .jpg files from the directory
    System.IO.FileInfo[] files = dirInfo.GetFiles("*.jpg");

    // Add each file name and full name including path
    // to the ListView.
    if (files != null)
    {
        foreach ( System.IO.FileInfo file in files )
        {
            ListViewItem item = new ListViewItem(file.Name);
            item.SubItems.Add(file.FullName);
            ListView1.Items.Add(item);
        }
    }
}
Private Sub PopulateListView()
    ListView1.Width = 270
    ListView1.Location = New System.Drawing.Point(10, 10)

    ' Declare and construct the ColumnHeader objects.
    Dim header1, header2 As ColumnHeader
    header1 = New ColumnHeader
    header2 = New ColumnHeader

    ' Set the text, alignment and width for each column header.
    header1.Text = "File name"
    header1.TextAlign = HorizontalAlignment.Left
    header1.Width = 70

    header2.TextAlign = HorizontalAlignment.Left
    header2.Text = "Location"
    header2.Width = 200

    ' Add the headers to the ListView control.
    ListView1.Columns.Add(header1)
    ListView1.Columns.Add(header2)

    ' Specify that each item appears on a separate line.
    ListView1.View = View.Details

    ' Populate the ListView.Items property.
    ' Set the directory to the sample picture directory.
    Dim dirInfo As New System.IO.DirectoryInfo _
        ("C:\Documents and Settings\All Users" _
        & "\Documents\My Pictures\Sample Pictures")
    Dim file As System.IO.FileInfo

    ' Get the .jpg files from the directory
    Dim files() As System.io.FileInfo = dirInfo.GetFiles("*.jpg")

    ' Add each file name and full name including path
    ' to the ListView.
    If (files IsNot Nothing) Then
        For Each file In files
            Dim item As New ListViewItem(file.Name)
            item.SubItems.Add(file.FullName)
            ListView1.Items.Add(item)
        Next
    End If
End Sub

注解

列标题是控件中 ListView 包含标题文本的项。 ColumnHeader可以使用 类的 ListView.ColumnHeaderCollection 方法将 对象添加到 。AddListView 若要将一组列添加到 ListView,可以使用 AddRange 类的 ListView.ColumnHeaderCollection 方法。 可以使用 Index 类的 ColumnHeader 属性来确定 在 中ListView.ColumnHeaderCollection的位置ColumnHeader

ColumnHeaderText提供 和 TextAlign 属性,用于设置控件中显示的文本以及列标题中文本的对齐方式。 若要确定 是否 ColumnHeaderListView 控件关联,可以引用 ListView 属性。 如果要复制 供另一个ColumnHeaderListView控件使用,可以使用 Clone 方法。

构造函数

ColumnHeader()

初始化 ColumnHeader 类的新实例。

ColumnHeader(Int32)

用指定的图像初始化 ColumnHeader 类的新实例。

ColumnHeader(String)

用指定的图像初始化 ColumnHeader 类的新实例。

属性

CanRaiseEvents

获取一个指示组件是否可以引发事件的值。

(继承自 Component)
Container

获取包含 IContainerComponent

(继承自 Component)
DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。

(继承自 Component)
DisplayIndex

相对于当前所显示各列,获取或设置列的显示顺序。

Events

获取附加到此 Component 的事件处理程序的列表。

(继承自 Component)
ImageIndex

获取或设置显示在 ColumnHeader 中的图像的索引。

ImageKey

获取或设置显示在列中的图像的键。

ImageList

获取 ColumnHeader 的关联图像列表。

Index

获取该列在 ListView 控件的 ListView.ColumnHeaderCollection 中的位置。

ListView

获取 ListView 所位于的 ColumnHeader 控件。

Name

获取或设置 ColumnHeader 的名称。

Site

获取或设置 ComponentISite

(继承自 Component)
Tag

获取或设置一个对象,该对象包含与 ColumnHeader 关联的数据。

Text

获取或设置列标题中显示的文本。

TextAlign

获取或设置 ColumnHeader 中所显示文本的水平对齐方式。

Width

获取或设置列的宽度。

方法

AutoResize(ColumnHeaderAutoResizeStyle)

按照调整大小样式调整列宽。

Clone()

创建当前 ColumnHeader 的相同副本,它未附加到任何列表视图控件。

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。

(继承自 MarshalByRefObject)
Dispose()

释放由 Component 使用的所有资源。

(继承自 Component)
Dispose(Boolean)

处置由 ColumnHeader 占用的资源(内存除外)。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetLifetimeService()
已过时.

检索控制此实例的生存期策略的当前生存期服务对象。

(继承自 MarshalByRefObject)
GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。

(继承自 Component)
GetType()

获取当前实例的 Type

(继承自 Object)
InitializeLifetimeService()
已过时.

获取生存期服务对象来控制此实例的生存期策略。

(继承自 MarshalByRefObject)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。

(继承自 MarshalByRefObject)
ToString()

返回包含 Component 的名称的 String(如果有)。 不应重写此方法。

事件

Disposed

在通过调用 Dispose() 方法释放组件时发生。

(继承自 Component)

适用于

另请参阅