Solved

Prevent Listview Columns From Being Selected

Posted on 2009-07-02
12
418 Views
Last Modified: 2013-11-26
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

0
Comment
Question by:jwr1966
[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
  • 6
  • 6
12 Comments
 
LVL 11

Expert Comment

by:G0ggy
ID: 24763857
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
 

Author Comment

by:jwr1966
ID: 24764013
No,
SelectedIndex is not available. Also SelectedItems is read only.
0
 
LVL 11

Expert Comment

by:G0ggy
ID: 24764064
SelectedIndex is a property and SelectedIndexChanged is an event of the ListView, can you explain why they're not available?
0
Technology Partners: 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!

 

Author Comment

by:jwr1966
ID: 24764127
Intelisense sais SelectedIndex is not a member of System.Windows.Forms.Listview. I am using 2008.
0
 
LVL 11

Expert Comment

by:G0ggy
ID: 24764249
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
 

Author Comment

by:jwr1966
ID: 24764444
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
 
LVL 11

Expert Comment

by:G0ggy
ID: 24765241
Does Enabled = False mess it up?
0
 

Author Comment

by:jwr1966
ID: 24765349
Yes,
When enabled is set to False the highlight stops working.
0
 
LVL 11

Assisted Solution

by:G0ggy
G0ggy earned 200 total points
ID: 24765542
Damn the luck...

Sorry mate I'm out of ideas. If I think of something overnight I'll post back.
0
 

Author Comment

by:jwr1966
ID: 24765618
Thank you for trying.
0
 

Accepted Solution

by:
jwr1966 earned 0 total points
ID: 24767015
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
 
LVL 11

Expert Comment

by:G0ggy
ID: 24767294
Splendid and cheers for posting back!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
A short article about problems I had with the new location API and permissions in Marshmallow
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

739 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