Solved

Set Focus on other Control after List View Selection Changed

Posted on 2014-02-11
6
780 Views
Last Modified: 2014-03-31
In my application there is a list view that when a selection is changed I would like to set the focus on a specific control. I am using the ItemSelectionChanged event to capture the change. And yes I know that the event fires twice and that is why if validate IsSelected.

After the event is fired, the focus returns to the list view. Very frustrating. I tried Do Events and a list view refresh before setting the focus and that did not work.

Side note: the function SetPayment updates several controls with information. There are no events attached to any of those controls.

    Private Sub lsvPayments_ItemSelectionChanged( _
        ByVal sender As Object, _
        ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) _
        Handles lsvPayments.ItemSelectionChanged

        SetPayment()
        If e.IsSelected Then
            txtRefundAmt.Focus()
            If Len(txtRefundAmt.Text) > 0 Then
                txtRefundAmt.SelectAll()
            End If
        End If
    End Sub

Open in new window

0
Comment
Question by:etsellinc
  • 4
  • 2
6 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39853738
What happens if you use the SelectedIndexChanged event instead?
0
 

Author Comment

by:etsellinc
ID: 39853859
Still the same action. The selection is made but then disappears and focus is reset to the list view.

Thanks for the response.

Mark
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39854239
Can you show the code you tried?

Do you have any code elsewhere which also changes focus of controls?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:etsellinc
ID: 39854495
Here is the code I tried. There is no code that sets the focus of controls anywhere on the form.


    Private Sub lsvPayments_SelectedIndexChanged( _
        ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles lsvPayments.SelectedIndexChanged
        txtRefundAmt.Focus()
        If Len(txtRefundAmt.Text) > 0 Then
            txtRefundAmt.SelectAll()
        End If
    End Sub

Open in new window

0
 

Accepted Solution

by:
etsellinc earned 0 total points
ID: 39883981
I ended up using the following code. It's not the best solution but it will have to do.

    Private Sub lsvPayments_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) _
        Handles lsvPayments.KeyUp
        txtRefundAmt.Focus()
        If Len(txtRefundAmt.Text) > 0 Then
            txtRefundAmt.SelectAll()
        End If
    End Sub

    Private Sub lsvPayments_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
        Handles lsvPayments.MouseUp
        txtRefundAmt.Focus()
        If Len(txtRefundAmt.Text) > 0 Then
            txtRefundAmt.SelectAll()
        End If
    End Sub

Open in new window

0
 

Author Closing Comment

by:etsellinc
ID: 39966091
Just a work-around. No one responded
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question