tag:blogger.com,1999:blog-4768571651580285164.post9085798474514533474..comments2023-06-03T07:32:53.823-05:00Comments on .NET Reference: Moving Listview Items Up or DownUnknownnoreply@blogger.comBlogger6125tag:blogger.com,1999:blog-4768571651580285164.post-2270526210965741462013-04-09T19:39:09.232-05:002013-04-09T19:39:09.232-05:00you can use this:
Private Sub lvSearch_KeyDown(By...you can use this:<br /><br />Private Sub lvSearch_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lvSearch.KeyDown<br /> If e.KeyCode = Keys.Down Then<br /><br /> If lvSearch.SelectedItems(0).Index < (lvSearch.Items.Count - 1) Then<br /><br /> txtName.Text = lvSearch.Items(lvSearch.SelectedItems(0).Index + 1).SubItems(1).Text<br /><br /> End If<br /> End If<br /> End Sub<br /><br /> Private Sub lvSearch_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lvSearch.KeyUp<br /> If e.KeyCode = Keys.Up Then<br /> If lvSearch.SelectedItems(0).Index >= 0 Then<br /><br /> txtName.Text = lvSearch.Items(lvSearch.SelectedItems(0).Index).SubItems(1).Text<br /><br /> End If<br /> End If<br /> End SubAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-4768571651580285164.post-13600689860478827912012-03-02T13:47:42.188-06:002012-03-02T13:47:42.188-06:00Private Sub MoveListViewItem(ByVal lvItem As ListV...Private Sub MoveListViewItem(ByVal lvItem As ListViewItem, ByVal Direction As enuDirection)<br /> Dim strTrace As String = "General Fault."<br /> Dim strRoutine As String = "MoveListViewItem"<br /> Try<br /> If Direction = enuDirection.Up Then<br /> strTrace = "Can't move the first item up."<br /> If lvItem.Index = 0 Then<br /> Exit Sub<br /> End If<br /><br /> strTrace = "Move the item up."<br /> Dim NewItem As ListViewItem = lvItem.Clone<br /> Me.lv_ActionPlan.Items.Insert(lvItem.Index - 1, NewItem)<br /> lvItem.Remove()<br /><br /> strTrace = "Select the item in its new location."<br /> NewItem.Selected = True<br /> Else<br /> strTrace = "Can't move the last item down."<br /> If lvItem.Index = Me.lv_ActionPlan.Items.Count - 1 Then<br /> Exit Sub<br /> End If<br /><br /> strTrace = "Move the item down."<br /> Dim NewItem As ListViewItem = lvItem.Clone<br /> Dim newIndex As Integer = lvItem.Index + 1<br /> lvItem.Remove()<br /> If newIndex > Me.lv_ActionPlan.Items.Count - 1 Then<br /> Me.lv_ActionPlan.Items.Add(NewItem)<br /> Else<br /> Me.lv_ActionPlan.Items.Insert(newIndex, NewItem)<br /> End If<br /><br /> strTrace = "Select the item in its new location."<br /> NewItem.Selected = True<br /> End If<br /><br /> Catch ex As Exception<br /> TraceLogger(strTrace, ex, strRoutine)<br /> ErrorLogger(ex.Message & " " & strTrace, Err.Number, strRoutine)<br /> End Try<br /> End SubUnknownhttps://www.blogger.com/profile/12208135034655826239noreply@blogger.comtag:blogger.com,1999:blog-4768571651580285164.post-68696946575796902572011-05-20T13:35:21.728-05:002011-05-20T13:35:21.728-05:00Hi,
it isnot woking within the groups.Hi,<br />it isnot woking within the groups.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4768571651580285164.post-1144083352297583712010-07-05T07:05:28.415-05:002010-07-05T07:05:28.415-05:00wow thanks later anon!wow thanks later anon!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4768571651580285164.post-73767426141286946642009-11-19T14:34:14.487-06:002009-11-19T14:34:14.487-06:00Try this:
Dim NewItem As ListViewI...Try this:<br /> Dim NewItem As ListViewItem = Me.lvPositions.SelectedItems(0).Clone<br /> Me.lvPositions.Items.Insert(Me.lvPositions.SelectedIndices(0) - 1, NewItem)<br /> Me.lvPositions.SelectedItems(0).Remove()<br /> NewItem.Selected = True<br /><br />RichardAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-4768571651580285164.post-48739828445334046302009-02-11T09:27:00.000-06:002009-02-11T09:27:00.000-06:00it also doesn't take into account multiselect list...it also doesn't take into account multiselect listviews, you'll then have to loop through the indexes of listView.SelectedItems.Anonymousnoreply@blogger.com