Export (0) Print
Expand All

ListView.AllowColumnReorder Property

Gets or sets a value indicating whether the user can drag column headers to reorder columns in the control.

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

Public Property AllowColumnReorder As Boolean

Property Value

Type: System.Boolean
true if drag-and-drop column reordering is allowed; otherwise, false. The default is false.

Setting the value of the AllowColumnReorder property has no effect unless the View property is set to Details. You can use this property to allow users to reposition columns in the control at run time. When the AllowColumnReorder property is set to true, users can position the columns in the control to display the item and its subitems in a way that meets their needs within your application.

The following code example creates a ListView control with three ListViewItem objects specified and three ListViewItem.ListViewSubItem objects specified for each item. The example also creates ColumnHeader objects to display the subitems in details view. Two ImageList objects are also created in the code example to provide images for the ListViewItem objects. These ImageList objects are added to the LargeImageList and SmallImageList properties. The example uses the following properties in creating the ListView control:

This example requires that you have added the code to a Form and call the method created in the example from the constructor or another method on the form. The example also requires that images named MySmallImage1, MySmallImage2, MyLargeImage1, and MyLargeImage2 are located in the root directory of drive C.

        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
            Dim item2 As New ListViewItem("item2", 1)
            Dim item3 As New ListViewItem("item3", 0)
            ' Place a check mark next to the item.
            item3.Checked = True

            ' 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.

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

            ' Add the ListView to the control collection. 
        End Sub 'CreateMyListView

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft