Prevent Listview Columns From Being Selected

Hello Experts,
I am building a Sequencing Engine to Control a PLC. I have a listview that has items loaded from a DB Table. Each Line Item is a String Version of the Commands being evaluated and are for visual reference only. As the Program runs each line is highlighted to show the user where the process is at. The Process and and the highlighting of the line item is done in a seperate thread. My issue is if the Listview is mouse clicked anywhere, the line item loses its highlight until the code moves to the next line. Can I prevent a mouseclick on the Listview at run time AND still allow checkboxes to be selected? This is also my first attempt at Threading.
Private FunctionThread As Thread = Nothing
    Delegate Sub RunSequence(ByVal SeqLine As Integer)
 
    Private Sub StartRunFunctionThread()
        ' Create a background thread and start it.
        Me.FunctionThread = New Thread( _
            New ThreadStart(AddressOf Me.ThreadRunFunction))
        Me.FunctionThread.IsBackground = True
        Me.FunctionThread.Start()
    End Sub
 
    Private Sub ThreadRunFunction()  
      ' Work is done in this Sub
        Dim S As New RunSequence(AddressOf RunFunction)
        Me.lstSequence.Invoke(S, New Object() {[StepNumber]})
    End Sub
 
    Private Sub RunFunction(ByVal LineNum As Integer)
        Me.lstSequence.Items(LineNum).Selected = True
        Me.lstSequence.Select()
        Me.lstSequence.Refresh()
    End Sub

Open in new window

jwr1966Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

G0ggyCommented:
Will this do it:

Protected Sub lstSequence_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstSequence.SelectedIndexChanged
        lstSequence.SelectedIndex = Nothing
    End Sub
0
jwr1966Author Commented:
No,
SelectedIndex is not available. Also SelectedItems is read only.
0
G0ggyCommented:
SelectedIndex is a property and SelectedIndexChanged is an event of the ListView, can you explain why they're not available?
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

jwr1966Author Commented:
Intelisense sais SelectedIndex is not a member of System.Windows.Forms.Listview. I am using 2008.
0
G0ggyCommented:
Sorry, my mistake, was reading this as ASP, will this work for you?

Private Sub ListView1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.GotFocus
        Button1.Focus() 'or somewhere else?
    End Sub
0
jwr1966Author Commented:
Nope, Good idea though. I even tried Mouseover to move the focus. But as soon as I click on the Listview the Highlight goes away.
0
G0ggyCommented:
Does Enabled = False mess it up?
0
jwr1966Author Commented:
Yes,
When enabled is set to False the highlight stops working.
0
G0ggyCommented:
Damn the luck...

Sorry mate I'm out of ideas. If I think of something overnight I'll post back.
0
jwr1966Author Commented:
Thank you for trying.
0
jwr1966Author Commented:
I found an answer. It is not elegant but it works well enough. I simply capture the highlighted line Item on the mousedown event and then re-highlight it on the mouseup event.

    Dim lineItem As Integer = 0
    Private Sub lstSequence_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstSequence.MouseDown
        For i As Integer = 0 To Me.lstSequence.Items.Count - 1
            If Me.lstSequence.Items(i).Selected = True Then
                lineItem = i
            End If
        Next
    End Sub

    Private Sub lstSequence_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstSequence.MouseUp
        If lineItem >= 0 Then
            Me.lstSequence.Items(lineItem).Selected = True
            Me.lstSequence.Select()
            Me.Refresh()
        End If
    End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
G0ggyCommented:
Splendid and cheers for posting back!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.