StrataFrame Forum

Move up and down list

http://forum.strataframe.net/Topic6566.aspx

By Chan - 2/5/2007

Hi,

I would like to have a list control that allow user to adjust record position by clicking move up/down. How does it usually be implemented using SF?

Thank you

By Joseph-Carl Theodat - 2/5/2007

Hi,

you can do it by adding two buttons (up & down) on your form and adjust the Items Collection of your ListBox control.

For the Up & Down: change the position of your current selected item in the collection

Be careful at the boundaries of your collection.

By Michael Reese - 2/5/2007

Hi Chan

You can use code something like this where LvNavigate is your listview.

Private Sub lvNavigate_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvNavigate.SelectedIndexChanged

If lvNavigate.SelectedItems.Count > 0 Then

Me.BoDevTools1.NavigateToPrimaryKey(CType(Me.lvNavigate.SelectedItems(0).Tag, Integer))

End If

End Sub

Private Sub BO_Navigated(ByVal e As MicroFour.StrataFrame.Business.NavigatedEventArgs) Handles BoDevTools1.Navigated

If BoDevTools1.Count > 0 Then

SetListViewIndex(BoDevTools1.ID)

End If

End Sub

Private Sub SetListViewIndex(ByVal PrimaryKey As Integer)

'-- Establish Locals

Dim loItem As ListViewItem

'-- Remove any selected items

For Each loItem In Me.lvNavigate.Items

'-- See if the item matches the PK

If CType(loItem.Tag, Integer) = PrimaryKey Then

'-- Select the list item

loItem.Selected = True

'-- Make sure it is visible

lvNavigate.EnsureVisible(lvNavigate.Items.IndexOf(loItem))

Else

'-- Turn off the selection

loItem.Selected = False

End If

Next

End Sub

Private Sub lvNavigate_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvNavigate.SelectedIndexChanged

If lvNavigate.SelectedItems.Count > 0 Then

Me.BoDevTools1.NavigateToPrimaryKey(CType(Me.lvNavigate.SelectedItems(0).Tag, Integer))

End If

End Sub

Private Sub BO_Navigated(ByVal e As MicroFour.StrataFrame.Business.NavigatedEventArgs) Handles BoDevTools1.Navigated

If BoDevTools1.Count > 0 Then

SetListViewIndex(BoDevTools1.ID)

End If

End Sub

Private Sub SetListViewIndex(ByVal PrimaryKey As Integer)

'-- Establish Locals

Dim loItem As ListViewItem

'-- Remove any selected items

For Each loItem In Me.lvNavigate.Items

'-- See if the item matches the PK

If CType(loItem.Tag, Integer) = PrimaryKey Then

'-- Select the list item

loItem.Selected = True

'-- Make sure it is visible

lvNavigate.EnsureVisible(lvNavigate.Items.IndexOf(loItem))

Else

'-- Turn off the selection

loItem.Selected = False

End If

Next

End Sub

By Trent L. Taylor - 2/6/2007

Joseph and Michael are both correct.  Generally, as Joseph had mentioned, we will add two buttons and then managed the index position of the list.  We will then manage the BO position through the SelectedIndexChanged event of the listview.  When we populate a ListView, especially if you are populating using a BO, you can store the PK of each row in the tag property (Michaels post mentions how to do this).  This will give you a value to seek on.  If you look at the AdvancedListViewPopulation sample, this sample gives you an example of this...as does the CRM sample application for the population of the credit cards in the customer maintenance.