ListView::ColumnHeaderCollection::Insert Method (Int32, String^, Int32, HorizontalAlignment)

 

Creates a new column header and inserts it into the collection at the specified index.

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

public:
void Insert(
	int index,
	String^ text,
	int width,
	HorizontalAlignment textAlign
)

Parameters

index
Type: System::Int32

The zero-based index location where the column header is inserted.

text
Type: System::String^

The text to display in the column header.

width
Type: System::Int32

The initial width of the column header. Set to -1 to autosize the column header to the size of the largest subitem text in the column or -2 to autosize the column header to the size of the text of the column header.

textAlign
Type: System.Windows.Forms::HorizontalAlignment

One of the HorizontalAlignment values.

Exception Condition
ArgumentOutOfRangeException

index is less than 0 or greater than or equal to the value of the Count property of the ListView::ColumnHeaderCollection.

This version of the Insert method enables you to create a new ColumnHeader with specific column header text, width, and text alignment setting and insert it at a specific position in the ListView::ColumnHeaderCollection. You can use this method if you want to insert a new column header into an existing collection of column headers. If you want to use an existing ColumnHeader and insert it at a specific position in the collection, use the other version of the Insert method. To add a column header without specifying a specific position in the collection, use the Add method. If you want to add an array of column headers to the collection, use the AddRange method.

.NET Framework
Available since 1.1
Return to top
Show: