Export (0) Print
Expand All

ListViewItem.Position Property

Gets or sets the position of the upper-left corner of the ListViewItem.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public Point Position { get; set; }
/** @property */
public Point get_Position ()

/** @property */
public void set_Position (Point value)

public function get Position () : Point

public function set Position (value : Point)

Not applicable.

Property Value

The Point at the upper-left corner of the ListViewItem.

Exception typeCondition

InvalidOperationException

The Position is set when the containing ListView is in virtual mode.

The Position property should be set after the ListViewItem and containing ListView are constructed. Changing the Position property when the containing ListView is in Details or List view will have no effect on the position of the items. Also, the Position property will automatically change when the View property of the containing ListView is changed from SmallIcon, LargeIcon, or Tile view to List or Details. When the ListView is in SmallIcon, LargeIcon, or Tile view, setting the Position property for an item will cause the other items contained in the ListView to be rearranged.

The following code example demonstrates how to use the Position property of a ListViewItem. To run this example, paste the following code into a Windows Form and call the InitializePositionedListViewItems from the form's Load event-handling method. Click the button to see the items repositioned.

private ListView positionListView;
private ListViewItem moveItem;
private Button button1;

private void InitializePositionedListViewItems()
{
    // Set some basic properties on the ListView and button.
    positionListView = new ListView();
    positionListView.Height = 200;
    button1 = new Button();
    button1.Location = new Point(160, 30);
    button1.AutoSize = true;
    button1.Text = "Click to reposition";
    button1.Click += new System.EventHandler(button1_Click);

    // View must be set to icon view to use the Position property.
    positionListView.View = View.LargeIcon;
  
    // Create the items and add them to the ListView.
    ListViewItem item1 = new ListViewItem("Click");
    ListViewItem item2 = new ListViewItem("OK");
    moveItem = new ListViewItem("Move");
    positionListView.Items.AddRange(new ListViewItem[] 
        { item1, item2, moveItem });

    // Add the controls to the form.
    this.Controls.Add(positionListView);
    this.Controls.Add(button1);
}

private void button1_Click(object sender, EventArgs e)
{
    moveItem.Position = new Point(30, 30);
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft