[RESOLVED] How do I highlight a single listview gridline?
please help, How do I highlight a single listview gridline?And how to make the checkboxes become disable after the checkboxes was Clicked?
This is the current code:
Code:
Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
If ListView1.CheckBoxes = True Then
ListView1.Gridlines = True
FrmLat.Show
End If
End Sub
please help.THANKS!
Re: How do I highlight a single listview gridline?
Quote:
How do I highlight a single listview gridline
Set the property .FullRowSelect = True
Quote:
And how to make the checkboxes become disable after the checkboxes was Clicked?
Try using the property .Tag = "L"
Hope this helps...
Re: How do I highlight a single listview gridline?
Quote:
Originally Posted by
koolsid
Try using the property .Tag = "L"
Can you explain the idea ? :confused:
Re: How do I highlight a single listview gridline?
Quote:
Originally Posted by
akhileshbc
Can you explain the idea ? :confused:
The 'idea' is an evil one :lol:
Code:
Private Sub Form_Load()
Dim lstItem As ListItem
For i = 1 To 5
Set lstItem = ListView1.ListItems.Add(, , "Sample Text" & Str$(i))
Next
'~~> so that item 1 cannot be unclicked.
ListView1.ListItems(1).Tag = "L"
End Sub
Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
If Item.Tag = "L" Then Item.Checked = True
If Item.Index = 1 Then Item.Checked = True
End Sub
One more alternative would be to fake it by using disbaled checkbox images. This reminds me on one thread where you use icons... Let me search the thread for you...
Edit: Damn! The link was in in my signature while all this time and I was searching for it... :lol: "Listview Sub Item Image" (See post 6 and post 8) in that thread...
Re: How do I highlight a single listview gridline?
Thanks sid for explaining it...:wave:
But can you check this one:
Code:
Option Explicit
Private Sub Form_Load()
Dim lstItem As ListItem
Dim i As Long
For i = 1 To 5
Set lstItem = ListView1.ListItems.Add(, , "Sample Text" & Str$(i))
Next
End Sub
Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
If Item.Checked = False Then Item.Checked = True '~~~ This will prevents the unchecking of the checkboxes.
End Sub
...:wave:
Re: How do I highlight a single listview gridline?
hi,thanks is done.but how to make the highlight listview gridlines appear when clicked checkboxes= true.
this is the current code:
Code:
Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
If ListView1.CheckBoxes = True Then
FrmLat.Show
ListView1.FullRowSelect = True 'highlight listview gridlines
End If
If Item.Checked = False Then Item.Checked = True
End Sub
please help.Thanks!
Re: How do I highlight a single listview gridline?
You don't have to set the FullRowSelect on every click/check event. Just set it once on Form Load or even in design mode. Also, this line
If Item.Checked = False Then Item.Checked = True
will make it impossible to uncheck an item.
To highligh the checked item try
Code:
Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
Item.Selected = True
End Sub
And, just to note because I think you missunderstood the purpose, If ListView1.CheckBoxes = True does not check if an item is Checked or not but if the ListView has checkboxes turned on or not. If you set it to false Checkboxes wont be displayed.
Re: How do I highlight a single listview gridline?
I think, for highlighting the items, try changing their font color from the default....:wave:
Eg:
[ ] Item1
[ ] Item2
[X] Item3
[ ] Item4
[X] Item5
Re: How do I highlight a single listview gridline?
@Akhi: Yes that will work too (I am refering to post 5). The .Tag can be used if you want specific listitems to display that behaviour. For example in the code that I gave in post 4, it is just specific to listitem 1
@Grace: Like Baja mentioned that you can set the FullRowSelect at design time. If you want to display it only if an item is checked then try this...
Code:
Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
'~~> Check if any item is checked in the listview
For i = 0 To ListView1.ListItems.Count
If ListViewName.ListItems.Item(i).Checked = True Then
ListView1.FullRowSelect = True
'FrmLat.Show
Exit For
Else
ListView1.FullRowSelect = False
End If
Next
'~~> Ensure that user is not able to uncheck
If Item.Checked = False Then Item.Checked = True
End Sub
Re: How do I highlight a single listview gridline?
Thanks for the info, sid...:wave:
Re: How do I highlight a single listview gridline?
koolsid:
hi ,i try to run the code as below:
Code:
If ListViewName.ListItems.Item(i).Checked = True Then
ListviewName show error Variable not defined.
please help thanks
Re: How do I highlight a single listview gridline?
I think he meant for you to replace ListViewName with the name of the Listview you have/use.
Re: How do I highlight a single listview gridline?
baja_yu:
i have changed the listviewname to listview1 ,but have another error message appaear " index out of bound".
please help.thanks!
Re: How do I highlight a single listview gridline?
Try changing the starting value from 0 to 1:
Code:
For i = 1 To ListView1.ListItems.Count
....:wave:
Re: How do I highlight a single listview gridline?
akhileshbc:
hi,the code is work.but when the for highlighting the items doesn't work.
Eg:
[ ] Item1
[ ] Item2
[X] Item3
[ ] Item4
[X] Item5
Code:
Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.listitem)
Dim i As Integer
For i = 1 To ListView1.ListItems.Count
If ListView1.ListItems.Item(i).Checked = True Then
ListView1.FullRowSelect = True
FrmLat.Show
Exit For
Else
ListView1.FullRowSelect = False
End If
Next
If Item.Checked = False Then Item.Checked = True
End Sub
Re: How do I highlight a single listview gridline?
Try this:
Code:
Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
'~~~ set the MultiSelect property of ListView to TRUE
Item.Selected = True
If Item.Checked = False Then Item.Checked = True
End Sub
Don't forget to set the MultiSelect property of ListView to TRUE.
Good luck...:thumb:
1 Attachment(s)
Re: How do I highlight a single listview gridline?
akhileshbc:
hi,thanks is done.now i have another problem appear when i selected the checkboxes on row 3 ,but the 1 row also highlighted.supposing is only highlight on selected checkboxes on row 3.
please help.thanks
Re: How do I highlight a single listview gridline?
Use this code in Form_Load event or after you populate the ListView:
Code:
ListView1.ListItems(1).Selected = False
It will unselect the 1st item. So, you can start a fresh selection...:wave:
Edit:
Sample usage:
Code:
Option Explicit
Private Sub Form_Load()
'~~~ Populating the ListView
ListView1.ListItems.Add , , "hi"
ListView1.ListItems.Add , , "hi"
ListView1.ListItems.Add , , "hi"
ListView1.ListItems.Add , , "hi"
ListView1.ListItems.Add , , "hi"
'~~~ Deselecting the first item
ListView1.ListItems(1).Selected = False
End Sub
Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
'~~~ set the MultiSelect option ListView to TRUE
Item.Selected = True
If Item.Checked = False Then Item.Checked = True
End Sub
Re: How do I highlight a single listview gridline?
akhileshbc:
thanks is work.
Ps:thanks all for help.:afrog:
Re: [RESOLVED] How do I highlight a single listview gridline?