Solved

Prevent Listview Columns From Being Selected

Posted on 2009-07-02
12
414 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
  • 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
 

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 76
Hide vba in gp 7 82
detecting  the added row index in a datagridview 3 54
Server Error 11 47
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
A short article about a problem I had getting the GPS LocationListener working.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

914 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

18 Experts available now in Live!

Get 1:1 Help Now