Results 1 to 16 of 16

Thread: Set Textbox Inside Listview SubItem [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,709

    Set Textbox Inside Listview SubItem [Resolved]

    I need to "Float" a textbox over a listview subitem to make the
    appearance of editing a subitem. I have the detection code for
    which subitem was clicked and row, but everything I found was
    using the x, y coordinates of the mouse click which does not
    accurately position the textbox within the sub item.

    How can I set a textbox coordinates to match the subitems
    rectangular coordinates? Maybe something like getting the RECT
    of the subitem somehow?

    Thanks.
    Last edited by RobDog888; Aug 19th, 2004 at 10:44 AM.
    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,709
    I found this constant so I think this is the correct path to take.
    VB Code:
    1. Public Const LVM_FIRST As Long = &H1000
    2. Public Const LVM_GETSUBITEMRECT As Long = (LVM_FIRST + 56)
    Anyone know how to get the coordinates? Probably SendMessage?
    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
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Hi RobDog,

    I seem to recall similar posts awhile back, this may have been one.




    Bruce.

  4. #4

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Its a little tacky, though. I am still searching. I thought I came
    across something using subclassing a long time ago. Hope I can
    find it.
    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

  5. #5

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    I think I'm on the right track now, but I'm having trouble using
    this function I found here

    Its the ListView_GetSubItemRect function. What is the value I
    should be passing for "code As Long"?
    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
    Hyperactive Member Dmitri K's Avatar
    Join Date
    Sep 2002
    Location
    West Palm Beach, FL
    Posts
    444
    RobDog,
    what I did is I created a flat textbox and just moved it to a given cell (curselrow and curselcolumn) and made the width/height of the textbox to the width of the columnheader. Although it's a cheap way, it works perfect. The only trick is, make sure the column is visible before displaying the textbox. I'll take a look at the code from the url you provided, maybe, if it's good enough, i'll replace my current functions with it.

  7. #7

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    I found a demo project at the site referenced by the thread. It
    looks promissing, but when your editing (showing the textbox)
    and the user scrolls the listview, the textbox does not move
    accordingly. Getting closer though. Logic is similar to what I was
    using to start and yours too.
    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
    Hyperactive Member Dmitri K's Avatar
    Join Date
    Sep 2002
    Location
    West Palm Beach, FL
    Posts
    444
    OK i got this rect thing to work. Add a listview, commandbutton, label and a textbox (no need to rename them or modify them):

    VB Code:
    1. Option Explicit
    2.  
    3. Const LVM_GETITEMRECT = (&H1000 + 14)
    4. Private Type RECT
    5.   Left As Long
    6.   Top As Long
    7.   Right As Long
    8.   Bottom As Long
    9. End Type
    10. 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
    11.  
    12. Private Sub Command1_Click()
    13.   Dim rec As RECT
    14.  
    15.   SendMessage ListView1.hWnd, LVM_GETITEMRECT, Val(Text1.Text) - 1, rec
    16.    
    17.   MsgBox "bottom: " & rec.Bottom & vbCrLf & _
    18.          "left: " & rec.Left & vbCrLf & _
    19.          "right: " & rec.Right & vbCrLf & _
    20.          "top: " & rec.Top
    21.  
    22. End Sub
    23.  
    24. Private Sub Form_Load()
    25.  
    26.   Dim iitem As ListItem
    27.   Dim x As Integer
    28.  
    29.   ListView1.View = lvwReport
    30.   ListView1.ColumnHeaders.Add , , "col1"
    31.   ListView1.ColumnHeaders.Add , , "col2"
    32.   Label1.Caption = "row:"
    33.   Text1.Text = "1"
    34.  
    35.   For x = 1 To 10
    36.     Set iitem = ListView1.ListItems.Add(, , "test" & x)
    37.       iitem.SubItems(1) = "testsub" & x
    38.   Next x
    39.  
    40. End Sub

    looks promissing, although my results returned pretty much the same values using columnwidth array. The only problem is the textbox refuses to stay the height i make it using row's height. I dont know why it always make itself 360 in height even if i make it 255 (default row height) or what not.
    Last edited by Dmitri K; Aug 17th, 2004 at 05:48 PM.

  9. #9

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    How come it always returns the left as 0 when I changed the
    message to LVM_GETSUBITEMRECT?
    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

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    You need to use the LVIR_LABEL constant to inform the
    sendmessage function that it is in report mode and get the label
    rect. Also, you need to populate the rect in the sendmessage api
    with the top and left properties only. Top = subitem index and left
    = LVIR_LABEL value.

    So I almost have it resolved except for the height and the left
    offset. It seems that it always puts the textbox a little to the right
    of the beginning of the subitem and the height does not
    completely fit. Perhaps because of the font size cant be chopped
    off.

    Ps. also use the setparent api to make the textbox a child of the
    listview so when it scrolls the textbox follows.
    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

  11. #11
    Hyperactive Member Dmitri K's Avatar
    Join Date
    Sep 2002
    Location
    West Palm Beach, FL
    Posts
    444
    Ok, well here's my code for this kind of stuff. By the way, the left and top are in offset beause of the border of the lsitview. For some reason with flat appearance it's still as with 3d appearance but the code below works for either.

    just add a listview and a textbox

    VB Code:
    1. Option Explicit
    2.  
    3. Private BMargin As Long
    4.  
    5. Private Sub Form_Load()
    6.   Dim aCol() As Variant, aColW() As Variant
    7.   Dim iItem As ListItem
    8.   Dim x As Integer
    9.  
    10.  
    11.   ListView1.View = lvwReport
    12.   ListView1.FullRowSelect = True
    13.   ListView1.GridLines = True
    14.   ListView1.LabelEdit = lvwManual
    15.   Text1.Appearance = 0
    16.  
    17.   aCol = Array("coltest1", "coltest2", "coltest3", "coltest4")
    18.   aColW = Array(1300, 1300, 600, 2000)
    19.  
    20.   For x = LBound(aCol) To UBound(aCol)
    21.     ListView1.ColumnHeaders.Add x + 1, , aCol(x)
    22.   Next x
    23.  
    24.   For x = 1 To 10
    25.     Set iItem = ListView1.ListItems.Add(, , "test" & x)
    26.       iItem.SubItems(1) = "testsub" & x
    27.       iItem.SubItems(2) = "testsub" & x
    28.       iItem.SubItems(3) = "testsub" & x
    29.   Next x
    30.  
    31.   Erase aCol, aColW
    32.  
    33.   If ListView1.Appearance = ccFlat Then
    34.     BMargin = 0
    35.   Else
    36.     BMargin = ListView1.GetFirstVisible.Left
    37.   End If
    38.  
    39. End Sub
    40.  
    41. Private Sub ListView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    42.  
    43.   Dim cnt As Integer
    44.   Dim CurCol As Integer
    45.  
    46.   With ListView1
    47.  
    48.     .SelectedItem = .HitTest(x, y)
    49.    
    50.     If Not .SelectedItem Is Nothing Then
    51.       For cnt = 1 To .ColumnHeaders.Count
    52.         If .ColumnHeaders.item(cnt).Left < x Then CurCol = cnt
    53.       Next cnt
    54.          
    55.       Text1.Move .ColumnHeaders.item(CurCol).Left + .Left + BMargin, .Top + .SelectedItem.Top + BMargin, .ColumnHeaders.item(CurCol).Width + BMargin, .SelectedItem.Height
    56.     End If
    57.   End With
    58.  
    59. End Sub

    see if it works better. If it doesn't than let me know, maybe I can use your method.

    Oh by the way, this code does not take into consideration if column is invisible (partially). The only way I know how to fix that is make listview the width of the (example) currentcol.left + currentcol.width.

    Just edited this post:
    hmm, this LVM_SCROLL scrolls horizontally. I'll see if i can make this work.
    Last edited by Dmitri K; Aug 17th, 2004 at 07:21 PM.

  12. #12

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    I like the demo, but not the hover effect. Kind of annoying.

    I think I found a simpler method to handel the user scrolling the
    listview when the textbox is being displayed. I disable them. This
    will be enabled when the textbox is hidden by way of esc or
    enter keys.

    By the way, you need to subclass the listview because if the user
    clicks somewhere outside of your app, the lost focus event will
    not fire and you will not be able to determine when to hide the
    textbox. You can trap for the WM_KILLFOCUS and WM_DESTROY
    messages. When you come accross them you hide the textbox
    setting the subitem's text back to original value.

    VB Code:
    1. Public Declare Function EnableScrollBar Lib "user32.dll" (ByVal hwnd As Long, ByVal wSBflags As Long, _
    2. ByVal wArrows As Long) As Long
    3.  
    4. 'SCROLLBAR CONSTS
    5. Public Const SB_HORZ As Long = 0
    6. Public Const SB_VERT As Long = 1
    7. Public Const SB_CTL As Long = 2
    8. Public Const SB_BOTH As Long = 3
    9.  
    10. Public Const ESB_DISABLE_BOTH = &H3
    11. Public Const ESB_DISABLE_DOWN = &H2
    12. Public Const ESB_DISABLE_LEFT = &H1
    13. Public Const ESB_DISABLE_RIGHT = &H2
    14. Public Const ESB_DISABLE_UP = &H1
    15. Public Const ESB_ENABLE_BOTH = &H0
    16.  
    17. 'Example of usage
    18. Call EnableScrollBar(ListView1.hwnd, SB_BOTH, ESB_DISABLE_BOTH)
    I think this may be good since I cant see why the user should
    be scrolling when they are supposed to be editing.

    What do you think?
    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

  13. #13

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

    If you use the common controls v. 5.0 for your listview you can
    use the SetParent api to link the textbox to the subitem. Then if
    the user scrolls the textbox will follow the subitem perfectly. I
    dont know why it doesn't work on 6.0 though? Otherwise you
    can just use the MapWindowPoints API to set the textbox to the
    subitem RECT.
    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

  14. #14

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Here is a demo of what I was thinking. I just don't like using
    the listview in common controls 5.0 for this. No full row select.
    Attached Files Attached Files
    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

  15. #15

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    I just went with the listview in common controls 6.0 and disabled
    the scrollbars. In 5.0 the setparent api works for scrolling but if
    you scroll beyond the viewable area then it gets messed up. So it
    looks like I will have to settle for disabling the scrollbars.

    Thanks to all.
    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

  16. #16
    Hyperactive Member mvrp350's Avatar
    Join Date
    Feb 2001
    Location
    Best, the Netherlands
    Posts
    322
    Hi RObDog888,

    I've been playing around with your editable listview.
    I'm not able to convert it for working with an array of listviews.
    Are you able to upgrade the code, so it will work with arrays?

    Thanks in advance

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