Moving items in a listview? up and down either dragging or with buttons


Author
Message
Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
I want to display the contents of a BO in a List/Listview/grid whatever for the sole purpose of the user being able to rearrange or modify the order of the list ( I will then write back the new position into the sequence number field of the table)



Ideally, I would use the new StratalistView control, but it would also be fine to use the current SF Listview. Dragging and dropping to new position with the mouse would be fine, selecting a using arrows to move would be fine or just having buttons to move the item up and down the way it is done with fields in DDT would be fine.



I think I'm missing something easy.



Suggestions?
Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Hey Charles!

Have you got an Order column on the table? Guess that if you have it, it has incremented values in it and the table ir ordered on it, when clicking the Up and Down button on your form could exchange the values from the selected row with the upper or lower row, according to which button was pressed.

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Hi Ivan



I thought about doing something like that but it seems the framework uses the buttons a lot for things like item lists and I thought there might be some command in the listview or something that could be called from the button that changes the item's position in the list. ????
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
This is something that we do a fair amount in the medical application. There are a number of places that we need to have things ranked. In these situations, we will create a toolstrip button for both up and down. Then create a single method that supports the entire logic and simply extract and re-insert the list item either ahead or behind (depending on moving up or down). Here is an example using the ListView. But you could do the same thing with the StrataListView:



Private Sub MoveItem(ByVal moveDown As Boolean)

If lstList.SelectedItems.Count = 0 Then Exit Sub



'-- Establish Locals

Dim item As ListViewItem

Dim index As Integer = lstList.SelectedIndices(0)



'-- Determine which way to move the item

If moveDown Then

'-- See if a move down is possible

If index = lstList.Items.Count - 1 Then Exit Sub



'-- Extract the item from the list

item = lstList.Items(index)

lstList.Items.Remove(item)



'-- Insert the item

lstList.Items.Insert(index + 1, item)

Else

'-- See if the item can be moved up

If lstList.SelectedIndices(0) = 0 Then Exit Sub



'-- Extract the item from the list

item = lstList.Items(index)

lstList.Items.Remove(item)



'-- Insert the item

lstList.Items.Insert(index - 1, item)

End If



'-- May need to update some toolbar items, menus, etc. after the change is made. Do that now.

SetMenuItems()

End Sub

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Thanks Trent.



I am about to try this with a listview and a stratalistview.



I assume moving an item moves the subitems along with it?

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Worked great on the listview. I'm putting into a shared sub in my util library and passing in the Listview by reference.



Will have another for the Stratalistview.



Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
I assume moving an item moves the subitems along with it?

Yes.  A sub item belongs to the actual item.  This is the same type of logic that the standard ListView used and we just followed suit to try and make the learning curve slightly less.

Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Yep, perfect!

Sorry for the silly idea, Charles.

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Ivan,



Nice to see you back! where have you been? w00t

Edhy Rijo

Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Hey Edhy!

Well... cruising around the world. (yep, I daydream)

Just too busy. But I was reading the posts every chance I got. Have read lots of yours, very good ones actually.

How've you been?

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search