Results 1 to 20 of 20

Thread: [RESOLVED] How do I highlight a single listview gridline?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Resolved [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!

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: How do I highlight a single listview gridline?

    How do I highlight a single listview gridline
    Set the property .FullRowSelect = True

    And how to make the checkboxes become disable after the checkboxes was Clicked?
    Try using the property .Tag = "L"

    Hope this helps...
    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

  3. #3
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: How do I highlight a single listview gridline?

    Quote Originally Posted by koolsid View Post
    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


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: How do I highlight a single listview gridline?

    Quote Originally Posted by akhileshbc View Post
    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

  5. #5
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    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


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    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!

  7. #7
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    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

  8. #8
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: How do I highlight a single listview gridline?

    I think, for highlighting the items, try changing their font color from the default....

    Eg:
    [ ] Item1
    [ ] Item2
    [X] Item3
    [ ] Item4
    [X] Item5

    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


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  9. #9
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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

  10. #10
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    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


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    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

  12. #12
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    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.

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    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!

  14. #14
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    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


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    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

  16. #16
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    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


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    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
    Attached Images Attached Images  

  18. #18
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    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


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: How do I highlight a single listview gridline?

    akhileshbc:
    thanks is work.

    Ps:thanks all for help.

  20. #20
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    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


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width