StrataFrame Forum

Keyboard behaviour with Listview Child form

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

By Andrew Harper - 10/13/2011

Hi,

We are looking to redevelop a major application for a client and as part of a pilot project I have developed a maintenance form that uses a listview with a child form. The users of our existing application are used to being able to do what they need via the keyboard with minimal use of the mouse.

I examined the Strataflix sample and developed the form using the same techniques as the Movie Database maintenance form. The problem we have is if the user presses downarrow after successfully editing a child record they are positioned on the first record in the listview not the record below the highlighted record that has just been edited.

This can be replicated in the Strataflix application as follows:

1. Choose the Movie Database and select the Find a Movie option

2. Enter "Gone with the Wind" in the browse dialogue, click search and choose the first movie listed

3. In the Cast Members list select  "Leigh, Vivien"

4. Click edit

5. Change the character name to "Scarlett O'Hara"

6. Click OK - the listview is updated and Vivien Leigh is highlighted and displayed correctly

7. Press downarrow

8. The listview highlights the first record in the list not the record below Vivien Leigh.

I suspect that the Listview is losing focus but have not been able to rectify the behaviour - any suggestions appreciated,

TIA

Andy
By Ivan George Borges - 10/13/2011

Hi Andrew.

First, create a Private Field to house the row index:

    Private _RowIndex As Integer = 0


Then, in the lstCast_ChildFormResults, set the row index before the listview gets requeried:

    Private Sub lstCast_ChildFormResults(ByVal sender As System.Object, ByVal e As MicroFour.StrataFrame.UI.Windows.Forms.ListViewChildFormResultsEventArgs) Handles lstCast.ChildFormResults
        If e.Results = Windows.Forms.DialogResult.Cancel Then
            MovieCast.RestoreCurrentDataTableSnapshot(False)
        Else
            _RowIndex = lstCast.FocusedItem.Index
            e.Requery = True
        End If
    End Sub


Finally, add an AfterRequery event handler for the listview to reset the row index:

    Private Sub lstCast_AfterRequery() Handles lstCast.AfterRequery
        lstCast.Items(_RowIndex).Selected = True
        lstCast.Items(_RowIndex).Focused = True
    End Sub


Boa noite!


 
By Andrew Harper - 10/14/2011

Hi Ivan,

Thanks for the prompt reponse - with some additional changes I now have the listview working correctly for add & delete as well as edit.

Best regards and thanks,

Andy
By Ivan George Borges - 10/14/2011

You're welcome, Andy.

Glad I could help. http://forum.strataframe.net/Skins/Classic/Images/EmotIcons/Cool.gif