By Charles R Hankey - 10/26/2009
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?
|
By Ivan George Borges - 10/26/2009
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.
|
By Charles R Hankey - 10/26/2009
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. ????
|
By Trent L. Taylor - 10/26/2009
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
|
By Charles R Hankey - 10/26/2009
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?
|
By Charles R Hankey - 10/26/2009
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.
|
By Trent L. Taylor - 10/26/2009
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.
|
By Ivan George Borges - 10/27/2009
Yep, perfect!Sorry for the silly idea, Charles.
|
By Edhy Rijo - 10/27/2009
Hi Ivan,
Nice to see you back! where have you been?
|
By Ivan George Borges - 10/27/2009
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?
|
By Greg McGuffey - 10/27/2009
I was noodling around with this with Charles and it worked great. We even made a component that you could drop on a form, set three properties and boom, order of items in listview is easily changeable. We made it specific to a SF ListView. He has the latest and greatest SF on Vista.
Then I tried to reproduce this in my environment, XP with 1.6.7. I used a plain old vanilla .NET ListView. It doesn't work. No matter what I use for this line as the index:
this.List.Items.Insert(index, item);
it inserts the item back in the same position. Thus:
this.List.Items.Insert(0, item);
this.List.Items.Insert(34, item);
this.List.Items.Insert(23454, item);
all put the item back exactly in the same position as it was to start. I.e. if the original index of the item is, say, 10, then each of these will put the item back at index 10.
Any ideas what might be causing this? I tried this with a target of 2.0 and 3.5. Same diff.
|
By Trent L. Taylor - 10/28/2009
This is a bit strange and without getting my hands on the code this could be hard to diagnose this way. This is ringing a bell with me but I can't put my finder on the answer....but it does sound familiar?!?
|
By Greg McGuffey - 10/28/2009
Here is a sample app. I'm pretty stumped. I upgraded to latest official release (1.7.0.2) and tried it on two machines. They are both XP though.
|
By Greg McGuffey - 10/30/2009
Has anyone had a chance to take a look at this yet?
|
By Trent L. Taylor - 10/30/2009
Nope
|