Highlighted Text

JarekM

Board Regular
Joined
Nov 13, 2018
Messages
86
Hi,
I need help. When I check a checkbox I want the text in listview to be highlighted in blue, I am having a problem where whenever I do check the checkbox the text does not highlight blue unless I move my cursor into the listview. Also whenever I check each individual checkbox in the listview it won't highlight in blue. but if I have the main checkbox checked and I have my cursor over the listview the text will be highlighted in blue and if wanted to uncheck each individual text then it won't unhighlight the text.

Here are some pictures for reference:

tinypic.com
[/URL][/IMG]

tinypic.com
[/URL][/IMG]

In the first picture I would have the checkbox checked, but the text won't be highlighted. In the second image we moved the cursor into the listview and the text was highlighted. I want it so it is highlighted even without having to move the cursor into the listview.

Here is also the code that I use:
Code:
Private Sub CheckBox3_Change()

Dim i As Integer
        
Call OptimizeCode_Start
        
        
        If CheckBox3.Value = True Then
            For i = 1 To lvRequests.ListItems.Count
                lvRequests.ListItems(i).Selected = True
                lvRequests.ListItems.Item(i).Checked = True
            Next i
        Else
            For i = 1 To lvRequests.ListItems.Count
                lvRequests.ListItems(i).Selected = False
                lvRequests.ListItems.Item(i).Checked = False
            Next i
        End If

Call OptimizeCode_End
        
        
        
End Sub


Thanks in advance
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
.
Untested here but does this work :

Code:
Private Sub CheckBox3_Change()


Dim i As Integer
        
Call OptimizeCode_Start
        
        
        If CheckBox3.Value = True Then
            For i = 1 To lvRequests.ListItems.Count
                lvRequests.ListItems(i).Selected = True
                lvRequests.ListItems.Item(i).Checked = True
            Next i
[B]        ElseIf CheckBox3.Value = False Then[/B]
            For i = 1 To lvRequests.ListItems.Count
                lvRequests.ListItems(i).Selected = False
                lvRequests.ListItems.Item(i).Checked = False
            Next i
        End If


Call OptimizeCode_End
        
        
        
End Sub
 
Upvote 0
I have tired the code, but it still won't work.
I actually have made a code where if I check an individual checkbox in the listview then the text will be highlighted, but I still have a problem where if I were to check the main checkbox that highlights every text in the listview, it still won't work if I check it.

I will attach all of the routines that refer to the listview, maybe they are the ones that cause the checkbox to not work properly:
Code:
Private Sub lvRequests_ItemCheck(ByVal Item As MSComctlLib.ListItem)
Dim i As Integer

lvRequests.ListItems(Item.Index).Selected = True

For i = 1 To lvRequests.ListItems.Count
    If lvRequests.ListItems(i).Checked = True Then
        lvRequests.ListItems.Item(i).Selected = True
        Else
        lvRequests.ListItems.Item(i).Selected = False
    End If
Next i

End Sub

Code:
Private Sub lvRequests_ItemClick(ByVal Item As MSComctlLib.ListItem)
Dim i As Integer

CheckBox3.Value = False

lvRequests.ListItems(Item.Index).Selected = True

For i = 1 To lvRequests.ListItems.Count
    If lvRequests.ListItems(i).Selected = True Then
        lvRequests.ListItems.Item(i).Checked = True
        Else
        lvRequests.ListItems.Item(i).Checked = False
    End If
Next i
End Sub

Code:
Private Sub lvRequests_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As stdole.OLE_XPOS_PIXELS, ByVal y As stdole.OLE_YPOS_PIXELS)
HookListBoxScroll1 Me, Me.lvRequests
End Sub

The third code I have so I can scroll on the mouse wheel in the listview.

Thank you.
 
Upvote 0
.
Please post your workbook for download. You will need to use a Cloud Site like DropBox.com
 
Upvote 0
.
Your workbook / code is missing a lot. The Listview control is absent / the checkboxes are absent.

Did you send the correct workbook ?
 
Upvote 0
Yes. I checked and everything that was needed was there. I even tested it out to see if it works on a different computer and it worked.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top