Results 1 to 11 of 11

Thread: Listview LabelEdit on Sub Items [Resolved]

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Listview LabelEdit on Sub Items [Resolved]

    How do you set the label edit on certain sub items and restrict on
    others? I toggle between automatic and manual as a way to lock
    the lvw. So when I want to allow editing, I need to let the user
    edit subitems also.

    Thanks.
    Last edited by RobDog888; Aug 17th, 2004 at 12:57 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  2. #2

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710
    If I can determine what sub item the click is in I guess I could
    show a textbox over the listview, but how to know which
    subitem?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710
    *BUMP*
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Here is code to determine which ListView SubItem was clicked. To run this example, just open a new project and put a ListView on the default Form. You'll also have to add a Module.

    In the Form:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.  
    5.     Dim LI As ListItem
    6.    
    7.     ListView1.View = lvwReport
    8.     ListView1.GridLines = True
    9.    
    10.     ListView1.ColumnHeaders.Add , , "Col1"
    11.     ListView1.ColumnHeaders.Add , , "Col2"
    12.     ListView1.ColumnHeaders.Add , , "Col3"
    13.    
    14.     Set LI = ListView1.ListItems.Add(, , "Item 1")
    15.     LI.SubItems(1) = "Item 1-SubItem 1"
    16.     LI.SubItems(2) = "Item 1-SubItem 2"
    17.    
    18.     Set LI = ListView1.ListItems.Add(, , "Item 2")
    19.     LI.SubItems(1) = "Item 2-SubItem 1"
    20.     LI.SubItems(2) = "Item 2-SubItem 2"
    21.    
    22.     Set LI = ListView1.ListItems.Add(, , "Item 3")
    23.     LI.SubItems(1) = "Item 3-SubItem 1"
    24.     LI.SubItems(2) = "Item 3-SubItem 2"
    25.    
    26. End Sub
    27.  
    28. Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    29.  
    30.     Dim lngItemIndex        As Long
    31.     Dim lngSubItemIndex     As Long
    32.     Dim strSubItemContent   As String
    33.  
    34.     GetLVCellData ListView1, X, Y, strSubItemContent, lngItemIndex, lngSubItemIndex
    35.    
    36.     MsgBox "You clicked Item # " & lngItemIndex & ", SubItem # " & lngSubItemIndex & "." _
    37.          & vbNewLine _
    38.          & "Contents: " & strSubItemContent
    39.  
    40. End Sub

    In the Module:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Const LVM_FIRST As Long = &H1000
    4. Private Const LVM_HITTEST As Long = (LVM_FIRST + 18)
    5. Private Const LVM_SUBITEMHITTEST As Long = (LVM_FIRST + 57)
    6. Private Const LVHT_ONITEMICON As Long = &H2
    7. Private Const LVHT_ONITEMLABEL As Long = &H4
    8. Private Const LVHT_ONITEMSTATEICON As Long = &H8
    9. Private Const LVHT_ONITEM As Long = (LVHT_ONITEMICON Or _
    10.                                     LVHT_ONITEMLABEL Or _
    11.                                     LVHT_ONITEMSTATEICON)
    12. Private Type POINTAPI
    13.   X As Long
    14.   Y As Long
    15. End Type
    16.  
    17. Private Type LVHITTESTINFO
    18.    pt As POINTAPI
    19.    flags As Long
    20.    iItem As Long
    21.    iSubItem  As Long
    22. End Type
    23.  
    24. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    25.  
    26. '-----------------------------------------------------------------------------
    27. Public Sub GetLVCellData(pobjLV As ListView, _
    28.                          psngX As Single, _
    29.                          psngY As Single, _
    30.                          ByRef pstrCellText As String, _
    31.                          ByRef plngItemIndex As Long, _
    32.                          ByRef plngSubItemIndex As Long)
    33. '-----------------------------------------------------------------------------
    34.    
    35.     Dim HTI As LVHITTESTINFO
    36.     Dim lst As ListItem
    37.  
    38.     With HTI
    39.         .pt.X = (psngX \ Screen.TwipsPerPixelX)
    40.         .pt.Y = (psngY \ Screen.TwipsPerPixelY)
    41.         .flags = LVHT_ONITEM
    42.     End With
    43.      
    44.     SendMessage pobjLV.hwnd, LVM_SUBITEMHITTEST, 0, HTI
    45.  
    46.     If (HTI.iItem > -1) Then
    47.  
    48.         Set lst = pobjLV.ListItems(HTI.iItem + 1)
    49.  
    50.         plngItemIndex = HTI.iItem + 1
    51.         plngSubItemIndex = HTI.iSubItem
    52.        
    53.         If HTI.iSubItem = 0 Then
    54.             pstrCellText = pobjLV.ListItems(HTI.iItem + 1).Text
    55.         Else
    56.             pstrCellText = pobjLV.ListItems(HTI.iItem + 1).SubItems(HTI.iSubItem)
    57.         End If
    58.     Else
    59.         pstrCellText = ""
    60.         plngItemIndex = 0
    61.         plngSubItemIndex = 0
    62.        
    63.     End If
    64.  
    65. End Sub
    "It's cold gin time again ..."

    Check out my website here.

  5. #5

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710
    Thanks BruceG. I have found another example here,
    but it does not correctly work when the columns are resized to
    the point that there needs a horizontal scrollbar displayed. Its
    like everything is scrolled but the hittest method does not
    compenstate for the shift.

    I will try out your example, but does it compensate for the
    horizontal scrollbar issue?

    Thanks again.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    I hadn't tried that before, but I just did and it works fine; the scrollbar should not be an issue.
    "It's cold gin time again ..."

    Check out my website here.

  7. #7

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710
    YES IT WORKS CORRECTLY!!!

    Thanks allot BruceG.

    One other thing, is it possible to invoke the .LabelEdit method on
    a subitem or do I have to present a textbox at the subitem
    location as a simulation?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Ah yes, the rest of the story ... as far as I know, you CANNOT invoke LabelEdit on a SubItem, only the main item. I believe you'll have to do the floating textbox thing ...
    "It's cold gin time again ..."

    Check out my website here.

  9. #9

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710
    Thanks.

    I didn't want to be wasting time going down a dead end.

    BTW: You should CodeBank your code! There wasn't any working
    submissions yet.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by RobDog888
    YES IT WORKS CORRECTLY!!!

    Thanks allot BruceG.

    One other thing, is it possible to invoke the .LabelEdit method on
    a subitem or do I have to present a textbox at the subitem
    location as a simulation?
    It is possible if you are using subclassing i think. I have seen some example in C++, but not in VB. There are some example of C++ implementation in CodeGuru, here is one http://www.codeguru.com/Cpp/controls...cle.php/c1077/

    My C++ API skills are not the greatest, so i wouldnt dare trying to port i it to VB. Any one wants to try out.

    I think placing a control over subitem for editing is better, this way you get more control, e.g placing a combo box, datetime picker etc....

    Rob, did you manage to place a text box control over sub item correctly? I cant seem to get the co-ordinates of the SubItem properly. Would it be possible to post your code?


    Thanks.

    Danial
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  11. #11

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710
    Here is my other thread that will give you more info on getting
    the subitem rect and placing a textbox in it to simulate the label
    edit. I will clean up and make a demo for you. Then I will post it there.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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