Results 1 to 5 of 5

Thread: move item in listview

  1. #1

    Thread Starter
    Hyperactive Member gmatteson's Avatar
    Join Date
    Feb 2002
    Location
    Rhode Island, USA
    Posts
    293

    move item in listview

    is there a way to move an item "up" in a listview?

    if the item is number 4 on the list, on button click, can i move that item up to number 3 on the list?

  2. #2
    Addicted Member PeteD's Avatar
    Join Date
    Jun 2003
    Location
    Sydney
    Posts
    158
    VB Code:
    1. Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    2.       ListView1.Items.Add("Item " & ListView1.Items.Count)
    3.    End Sub
    4.  
    5.    Private Sub btnUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUp.Click
    6.       If ListView1.SelectedItems.Count = 1 Then
    7.          Dim lvItem As ListViewItem = ListView1.SelectedItems(0)
    8.          Dim newIndex As Integer = lvItem.Index - 1
    9.          If newIndex >= 0 Then
    10.             ListView1.Items.Remove(lvItem)
    11.             ListView1.Items.Insert(newIndex, lvItem)
    12.          End If
    13.       End If
    14.    End Sub

  3. #3

    Thread Starter
    Hyperactive Member gmatteson's Avatar
    Join Date
    Feb 2002
    Location
    Rhode Island, USA
    Posts
    293

    on click..

    when i click the move up button, nothing seems to happen to the items in the listview....it just blinks then thats it. sorry for the late reply, i've been gone for a day. it's also a two column listview if that will help at all. thanks again.
    Last edited by gmatteson; Aug 7th, 2003 at 05:35 AM.

  4. #4
    Addicted Member PeteD's Avatar
    Join Date
    Jun 2003
    Location
    Sydney
    Posts
    158
    works for me.....

    Have you selected an item before you click up?

    Try a new test project with just a form, a listview and two buttons.

  5. #5

    Thread Starter
    Hyperactive Member gmatteson's Avatar
    Join Date
    Feb 2002
    Location
    Rhode Island, USA
    Posts
    293

    yes

    i've select an item, then clicked move up...i noticed that the lvwitem is being refered to the data in column2...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width