Solved

Prevent Listview Columns From Being Selected

Posted on 2009-07-02
12
407 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
Comment Utility
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
Comment Utility
No,
SelectedIndex is not available. Also SelectedItems is read only.
0
 
LVL 11

Expert Comment

by:G0ggy
Comment Utility
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
Comment Utility
Intelisense sais SelectedIndex is not a member of System.Windows.Forms.Listview. I am using 2008.
0
 
LVL 11

Expert Comment

by:G0ggy
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 11

Expert Comment

by:G0ggy
Comment Utility
Does Enabled = False mess it up?
0
 

Author Comment

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

Assisted Solution

by:G0ggy
G0ggy earned 200 total points
Comment Utility
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
Comment Utility
Thank you for trying.
0
 

Accepted Solution

by:
jwr1966 earned 0 total points
Comment Utility
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
Comment Utility
Splendid and cheers for posting back!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
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…

743 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

16 Experts available now in Live!

Get 1:1 Help Now