Handling ListView Check Changes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a ListView control in Details view. When an item is un-checked, I
want to change the ForeColor.

The only way I have found to do this is to loop through all the items of the
ListView in its Click, DoubleClick, and KeyPress events using the sub below
.. However, the ListView can potentially hold hundreds of items, so this
would be quite slow.

Is there a better way to handle when an item is checked/un-checked?

Thank you,

Eric

\\\
Private Sub HandleCheckChange()
Dim item As ListViewItem
For Each item In lvwDirectories.Items
If item.Checked Then
item.ForeColor = SystemColors.WindowText
Else
item.ForeColor = SystemColors.GrayText
End If
Next
End Sub
///
 
What about ListView.ItemCheck event. Didn't it do the trick for you?
 
Oh, brother. I didn't even see the ItemCheck event. Thank you for your
help, Stoitcho.

Please accept my apologies for my ignorance. ;-)

Eric


Stoitcho Goutsev (100) said:
What about ListView.ItemCheck event. Didn't it do the trick for you?

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Hello,

I have a ListView control in Details view. When an item is un-checked, I
want to change the ForeColor.

The only way I have found to do this is to loop through all the items of the
ListView in its Click, DoubleClick, and KeyPress events using the sub below
. However, the ListView can potentially hold hundreds of items, so this
would be quite slow.

Is there a better way to handle when an item is checked/un-checked?

Thank you,

Eric

\\\
Private Sub HandleCheckChange()
Dim item As ListViewItem
For Each item In lvwDirectories.Items
If item.Checked Then
item.ForeColor = SystemColors.WindowText
Else
item.ForeColor = SystemColors.GrayText
End If
Next
End Sub
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top