ColumnHeader Class

 

Displays a single column header in a ListView control.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

System.Object
  System.MarshalByRefObject
    System.ComponentModel.Component
      System.Windows.Forms.ColumnHeader

[TypeConverterAttribute(typeof(ColumnHeaderConverter))]
public class ColumnHeader : Component, ICloneable

NameDescription
System_CAPS_pubmethodColumnHeader()

Initializes a new instance of the ColumnHeader class.

System_CAPS_pubmethodColumnHeader(Int32)

Initializes a new instance of the ColumnHeader class with the image specified.

System_CAPS_pubmethodColumnHeader(String)

Initializes a new instance of the ColumnHeader class with the image specified.

NameDescription
System_CAPS_protpropertyCanRaiseEvents

Gets a value indicating whether the component can raise an event.(Inherited from Component.)

System_CAPS_pubpropertyContainer

Gets the IContainer that contains the Component.(Inherited from Component.)

System_CAPS_protpropertyDesignMode

Gets a value that indicates whether the Component is currently in design mode.(Inherited from Component.)

System_CAPS_pubpropertyDisplayIndex

Gets or sets the display order of the column relative to the currently displayed columns.

System_CAPS_protpropertyEvents

Gets the list of event handlers that are attached to this Component.(Inherited from Component.)

System_CAPS_pubpropertyImageIndex

Gets or sets the index of the image displayed in the ColumnHeader.

System_CAPS_pubpropertyImageKey

Gets or sets the key of the image displayed in the column.

System_CAPS_pubpropertyImageList

Gets the image list associated with the ColumnHeader.

System_CAPS_pubpropertyIndex

Gets the location with the ListView control's ListView.ColumnHeaderCollection of this column.

System_CAPS_pubpropertyListView

Gets the ListView control the ColumnHeader is located in.

System_CAPS_pubpropertyName

Gets or sets the name of the ColumnHeader.

System_CAPS_pubpropertySite

Gets or sets the ISite of the Component.(Inherited from Component.)

System_CAPS_pubpropertyTag

Gets or sets an object that contains data to associate with the ColumnHeader.

System_CAPS_pubpropertyText

Gets or sets the text displayed in the column header.

System_CAPS_pubpropertyTextAlign

Gets or sets the horizontal alignment of the text displayed in the ColumnHeader.

System_CAPS_pubpropertyWidth

Gets or sets the width of the column.

NameDescription
System_CAPS_pubmethodAutoResize(ColumnHeaderAutoResizeStyle)

Resizes the width of the column as indicated by the resize style.

System_CAPS_pubmethodClone()

Creates an identical copy of the current ColumnHeader that is not attached to any list view control.

System_CAPS_pubmethodCreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodDispose()

Releases all resources used by the Component.(Inherited from Component.)

System_CAPS_protmethodDispose(Boolean)

Disposes of the resources (other than memory) used by the ColumnHeader.(Overrides Component.Dispose(Boolean).)

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Releases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection.(Inherited from Component.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_protmethodGetService(Type)

Returns an object that represents a service provided by the Component or by its Container.(Inherited from Component.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodInitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodToString()

Returns a String containing the name of the Component, if any. This method should not be overridden.(Overrides Component.ToString().)

NameDescription
System_CAPS_pubeventDisposed

Occurs when the component is disposed by a call to the Dispose method. (Inherited from Component.)

A column header is an item in a ListView control that contains heading text. ColumnHeader objects can be added to a ListView using the Add method of the ListView.ColumnHeaderCollection class. To add a group of columns to a ListView, you can use the AddRange method of the ListView.ColumnHeaderCollection class. You can use the Index property of the ColumnHeader class to determine where the ColumnHeader is located in the ListView.ColumnHeaderCollection.

ColumnHeader provides the Text and TextAlign properties to set the text displayed in the control and the alignment of the text in the column header. To determine whether a ColumnHeader is associated with a ListView control, you can reference the ListView property. If you want to copy a ColumnHeader for use in another ListView control, you can use the Clone method.

The following code example demonstrates initializing a ListView control. The example creates ColumnHeader objects and sets the column header's Text, TextAlign and Width properties. The example also adds items and subitems to the ListView. To run this example paste the following code in a form and call the PopulateListView method from the form's constructor or Load event handler.

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);
		}
	}
}

.NET Framework
Available since 1.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: