[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
Re: How do I highlight a single listview gridline?
Originally Posted by koolsid
Try using the property .Tag = "L"
Can you explain the idea ?
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
Re: How do I highlight a single listview gridline?
Originally Posted by akhileshbc
Can you explain the idea ?
The 'idea' is an evil one
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... "Listview Sub Item Image" (See post 6 and post 8) in that thread...
Last edited by Siddharth Rout; May 19th, 2010 at 05:53 AM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Re: How do I highlight a single listview gridline?
Thanks sid for explaining it...
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
...
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
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
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.
Last edited by baja_yu; May 21st, 2010 at 12:17 AM.
Reason: typo
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
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
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Re: How do I highlight a single listview gridline?
Thanks for the info, sid...
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
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
....
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
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...
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
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.
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...
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
Last edited by akhileshbc; May 21st, 2010 at 04:39 AM.
Reason: added sample usage
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
Re: [RESOLVED] How do I highlight a single listview gridline?
You're welcome...
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India