Chopper1980 Posted April 16, 2004 Posted April 16, 2004 I am trying to create a "Move Up" and "Move Down" button on a windows form to move a selected entry in a listview box to be moved either up or down, one position at a time... Any suggestions for this newbie? Quote
AlexCode Posted April 16, 2004 Posted April 16, 2004 I believe something like this will do the trick... Private Sub btMoveUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btMoveUp.Click If Me.ListView1.SelectedIndices.Count = 0 Then MessageBox.Show("You need to select an item first...") Exit Sub ElseIf Me.ListView1.SelectedIndices.Count > 1 Then MessageBox.Show("This code only supports single selection...") Exit Sub End If Dim SelIndex As Integer = Me.ListView1.SelectedIndices.Item(0) 'ListVisw must only support single seleccion If SelIndex = 0 Then MessageBox.Show("The selected item is already on top...") Exit Sub End If 'Reorder items in the arraylist Dim tItem As ListViewItem tItem = Me.ListView1.Items(SelIndex - 1) Me.ListView1.Items(SelIndex - 1) = Me.ListView1.Items(SelIndex).Clone Me.ListView1.Items(SelIndex) = tItem.Clone End Sub The messages are just to show how you can validate the action... Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
Chopper1980 Posted April 17, 2004 Author Posted April 17, 2004 (edited) Cheers mate.. that worked an absolute treat but where do i edit the code to get the "Move Down" button working? Thanks Edited April 17, 2004 by Chopper1980 Quote
AlexCode Posted April 17, 2004 Posted April 17, 2004 I usually leave something to figure out... only this way is possible to learn how to program... This is very easy matte... try to dig it out of your head... If still "no can do" tell me... Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
Chopper1980 Posted April 17, 2004 Author Posted April 17, 2004 i thought that it would just be a case of changing the selected index from - 1 to + 1 but it isn't having any of it..... am i along the right lines? Quote
AlexCode Posted April 17, 2004 Posted April 17, 2004 I was just a matter of changing signals... Private Sub btDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btDown.Click If Me.ListView1.SelectedIndices.Count = 0 Then MessageBox.Show("You need to select an item first...") Exit Sub ElseIf Me.ListView1.SelectedIndices.Count > 1 Then MessageBox.Show("This code only supports single selection...") Exit Sub End If Dim SelIndex As Integer = Me.ListView1.SelectedIndices.Item(0) 'ListVisw must only support single seleccion If SelIndex = Me.ListView1.Items.Count - 1 Then MessageBox.Show("The selected item is already on bottom...") Exit Sub End If 'Reorder items in the arraylist Dim tItem As ListViewItem tItem = Me.ListView1.Items(SelIndex + 1) Me.ListView1.Items(SelIndex + 1) = Me.ListView1.Items(SelIndex).Clone Me.ListView1.Items(SelIndex) = tItem.Clone End Sub Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
Chopper1980 Posted April 17, 2004 Author Posted April 17, 2004 to be honest.. that is what i thought i had done... but mine didn't work... never mind thanks for your help.. much appreciated Quote
AlexCode Posted April 17, 2004 Posted April 17, 2004 Just to add... This FREE ListView might help you in some ocasions... :D http://www.glacialcomponents.com/ProdDetail.aspx?pid=GlacialList Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.