We help IT Professionals succeed at work.

Prevent Listview Columns From Being Selected

jwr1966
jwr1966 asked
on
Medium Priority
447 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

Comment
Watch Question

CERTIFIED EXPERT

Commented:
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

Author

Commented:
No,
SelectedIndex is not available. Also SelectedItems is read only.
CERTIFIED EXPERT

Commented:
SelectedIndex is a property and SelectedIndexChanged is an event of the ListView, can you explain why they're not available?

Author

Commented:
Intelisense sais SelectedIndex is not a member of System.Windows.Forms.Listview. I am using 2008.
CERTIFIED EXPERT

Commented:
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

Author

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.
CERTIFIED EXPERT

Commented:
Does Enabled = False mess it up?

Author

Commented:
Yes,
When enabled is set to False the highlight stops working.
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thank you for trying.
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT

Commented:
Splendid and cheers for posting back!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.