Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Set Focus on other Control after List View Selection Changed

Posted on 2014-02-11
6
Medium Priority
?
817 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

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!

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

596 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