Solved

Set Focus on other Control after List View Selection Changed

Posted on 2014-02-11
6
776 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
Crystal reports vb.net 2 54
Import Data from Multiple Text Files in Excel 12 61
Iteration Help (Asp.net VB) 5 24
How to repeat the data 4 18
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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

828 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