ListView.AutoResizeColumn(Int32, ColumnHeaderAutoResizeStyle) ListView.AutoResizeColumn(Int32, ColumnHeaderAutoResizeStyle) ListView.AutoResizeColumn(Int32, ColumnHeaderAutoResizeStyle) ListView.AutoResizeColumn(Int32, ColumnHeaderAutoResizeStyle) Method

定義

特定の列の幅を、サイズ変更スタイルで示された幅にサイズ変更します。Resizes the width of the given column as indicated by the resize style.

public:
 void AutoResizeColumn(int columnIndex, System::Windows::Forms::ColumnHeaderAutoResizeStyle headerAutoResize);
public void AutoResizeColumn (int columnIndex, System.Windows.Forms.ColumnHeaderAutoResizeStyle headerAutoResize);
member this.AutoResizeColumn : int * System.Windows.Forms.ColumnHeaderAutoResizeStyle -> unit
Public Sub AutoResizeColumn (columnIndex As Integer, headerAutoResize As ColumnHeaderAutoResizeStyle)

パラメーター

columnIndex
Int32 Int32 Int32 Int32

サイズを変更する列の 0 から始まるインデックス。The zero-based index of the column to resize.

例外

columnIndex 場合は 0 より大きいColumnsnullcolumnIndex is greater than 0 when Columns is null

- または --or- columnIndex 0 未満か、列セットの数を超えています。columnIndex is less than 0 or greater than the number of columns set.

headerAutoResizeColumnHeaderAutoResizeStyle 列挙体のメンバーではありません。headerAutoResize is not a member of the ColumnHeaderAutoResizeStyle enumeration.

次の例では、初期化、ListView詳細ビューと自動的を使用して列のサイズを変更、AutoResizeColumnメソッド。The following example initializes a ListView in detail view and automatically resizes the columns using the AutoResizeColumn method. この例を実行するには、Windows フォームと呼び出しにこのコードを貼り付ける、InitializeResizingListViewフォームのコンス トラクターのメソッドまたはLoadイベント ハンドラー。To run this example, paste this code into a Windows Form and call the InitializeResizingListView method from the form's constructor or Load event handler.

private ListView resizingListView = new ListView();
private Button button1 = new Button();

private void InitializeResizingListView()
{
    // Set location and text for button.
    button1.Location = new Point(100, 15);
    button1.Text = "Resize";
    button1.Click += new EventHandler(button1_Click);

    // Set the ListView to details view.
    resizingListView.View = View.Details;

    //Set size, location and populate the ListView.
    resizingListView.Size = new Size(200, 100);
    resizingListView.Location = new Point(40, 40);
    resizingListView.Columns.Add("HeaderSize");
    resizingListView.Columns.Add("ColumnContent");
    ListViewItem listItem1 = new ListViewItem("Short");
    ListViewItem listItem2 = new ListViewItem("Tiny");
    listItem1.SubItems.Add(new ListViewItem.ListViewSubItem( 
            listItem1, "Something longer"));
    listItem2.SubItems.Add(new ListViewItem.ListViewSubItem(
        listItem2, "Something even longer"));
    resizingListView.Items.Add(listItem1);
    resizingListView.Items.Add(listItem2);

    // Add the ListView and the Button to the form.
    this.Controls.Add(resizingListView);
    this.Controls.Add(button1);
}

private void button1_Click(object sender, EventArgs e)
{
    resizingListView.AutoResizeColumn(0, 
        ColumnHeaderAutoResizeStyle.HeaderSize);
    resizingListView.AutoResizeColumn(1, 
        ColumnHeaderAutoResizeStyle.ColumnContent);
}

Private resizingListView As New ListView()
Private WithEvents button1 As New Button()


Private Sub InitializeResizingListView()
    ' Set location and text for button.
    button1.Location = New Point(100, 15)
    button1.Text = "Resize"
    AddHandler button1.Click, AddressOf button1_Click

    ' Set the ListView to details view.
    resizingListView.View = View.Details

    'Set size, location and populate the ListView.
    resizingListView.Size = New Size(200, 100)
    resizingListView.Location = New Point(40, 40)
    resizingListView.Columns.Add("HeaderSize")
    resizingListView.Columns.Add("ColumnContent")
    Dim listItem1 As New ListViewItem("Short")
    Dim listItem2 As New ListViewItem("Tiny")
    listItem1.SubItems.Add(New ListViewItem.ListViewSubItem(listItem1, _
        "Something longer"))
    listItem2.SubItems.Add(New ListViewItem.ListViewSubItem(listItem2, _
        "Something even longer"))
    resizingListView.Items.Add(listItem1)
    resizingListView.Items.Add(listItem2)

    ' Add the ListView and the Button to the form.
    Me.Controls.Add(resizingListView)
    Me.Controls.Add(button1)

End Sub


Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
    Handles button1.Click

    ' Resize the first column to the header size.
    resizingListView.AutoResizeColumn(0, _
        ColumnHeaderAutoResizeStyle.HeaderSize)

    ' Resize the second column to the column content.
    resizingListView.AutoResizeColumn(1, _
        ColumnHeaderAutoResizeStyle.ColumnContent)

End Sub

注釈

このメソッドを呼び出すことは有効な 1 回、ListViewを格納しているとFormが構築済みで、ListView列ヘッダーと列は項目が入力されます。Calling this method is only effective once the ListView and containing Form have been constructed, and the ListView column headers and columns are populated with items. 新しい項目を追加する場合、 ListView、サイズしない限り、列が変更されないAutoResizeColumnが再度呼び出されます。If new items are added to the ListView, the columns will not resize unless AutoResizeColumn is called again.

適用対象