Solved

Set Focus on other Control after List View Selection Changed

Posted on 2014-02-11
6
750 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Copy Data from one datatable to another datatable. 8 55
Vb.Net Menu 1 22
Paging GridView 7 34
Trouble with References... 5 22
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…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now