?
Solved

Set Focus on other Control after List View Selection Changed

Posted on 2014-02-11
6
Medium Priority
?
798 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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 this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

771 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