Results 1 to 15 of 15

Thread: [RESOLVED] Create an ComboBox inside a Listview

  1. #1

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Resolved [RESOLVED] Create an ComboBox inside a Listview

    What I want to do is to create a combobox on each line of my Listbox. I assume you can't do this so I will opt for a ListView. Possible???

    I want to select items from the combobox for each line in the list.
    Last edited by randem; May 19th, 2008 at 03:11 AM.

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

    Re: Create an ComboBox inside a Listview

    You cant do it with either. What you can do is "float" the cbo in the proper RECT are of your listview subitem. The main problems are when the user scrolls the listview as your cbos wont scroll with it. For this you are better off doing it in C++
    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
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Create an ComboBox inside a Listview

    Ok, thanks. That will keep me from doing all kinds of test...

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Create an ComboBox inside a Listview

    You could do it using a MSFlexgrid. This is from one of my old (and I mean OLD programs)
    Code:
    'cboCell is the name of the combo box and msfCarlines is the name of the MSFlexGrid
    
    Private Sub Form_Load()
    Dim i As Long   
        ' Prepare grid
        With msfCarlines
            .Top = 0
            .Width = Me.Width
            .Height = Me.Height
            .Left = 0
            For i = 0 To msfCarlines.Cols - 1
                .RowHeight(i) = cboCell.Height
            Next 
        End With
    End Sub
    
    'Put SetUpCombo In the Grids Click Event
    Private Sub SetupCombo()
    ' Setup the combobox by positioning and sizing it over the
    ' current flexgrid cell
    
    Dim sngL As Single
    Dim sngT As Single
    Dim sngW As Single
    Dim sngH As Single
      
        With msfCarlines.Container
            sngL = .ScaleX(msfCarlines.CellLeft, vbTwips, .ScaleMode)
            sngT = .ScaleY(msfCarlines.CellTop, vbTwips, .ScaleMode)
            sngW = .ScaleX(msfCarlines.CellWidth, vbTwips, .ScaleMode)
            sngH = .ScaleY(msfCarlines.CellHeight, vbTwips, .ScaleMode)
        End With
      
        With cboCell
            .Move msfCarlines.Left + sngL, msfCarlines.Top + sngT, sngW
            .Visible = True
            .SetFocus
        End With
      
    End Sub

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

    Re: Create an ComboBox inside a Listview

    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

  6. #6

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Create an ComboBox inside a Listview

    Hack,

    This way has promise. I am testing it and modifying your code. I will let you know how it turns out and report modifications.

  7. #7
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: Create an ComboBox inside a Listview

    Hey guys (hi Randem - how have you been?), a couple of years back I found some free code (I believe it was on this forum) for a way to implement an "editable listview". It uses the "floating" concept mentioned by RobDog, but the scrolling issue he speaks of is solved. The guy who posted the code mentioned that while it was basically working, he hadn't perfected it. But since I've been using it, I tweaked it some, and I have used this technique in many apps now - I typically float a textbox or combo on the desired cell, but a datepicker will work as well.

    What I'll do is put together a brief demo and post it back here.
    "It's cold gin time again ..."

    Check out my website here.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Create an ComboBox inside a Listview

    Quote Originally Posted by randem
    Hack,

    This way has promise. I am testing it and modifying your code. I will let you know how it turns out and report modifications.
    Yes, please do. I would be interested.

    As far as I know, that old app is still being used so you should be able to tweak it to fit your needs.

  9. #9
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: Create an ComboBox inside a Listview

    Here's the "Editable ListView" demo. Let me know how you make out.
    Attached Files Attached Files
    "It's cold gin time again ..."

    Check out my website here.

  10. #10

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Create an ComboBox inside a Listview

    Hey BruceG,

    Actually, I have solved the scrolling issue. But I will look at your demo to see what it has to offer. I will post my modifications to Hacks code when I sort out a resizing of the grid to the complete visible rows...

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

    Re: Create an ComboBox inside a Listview

    Hey Bruce. I had previously just disabled scrolling while a control was being floated was how I got around the issue before but its not all that elegant. I think we were working on the same code/thread several years ago? I'll try to find it.

    Edit: found it - http://www.vbforums.com/showthread.php?t=301372
    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

  12. #12

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Create an ComboBox inside a Listview

    Here is what i have so far. I have on minor bug in the last visible cell. It is always displaying the wrong ComboBox.
    Attached Files Attached Files

  13. #13
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Create an ComboBox inside a Listview

    I can see a couple of problems, one quite easy to resolve, the other probably needs more knowledge on FlexGrids, or a clearer understanding of the logic, than I have.

    Easy one: In Function GetVisibleRows, 'Count' is zero based so I suspect that you need 'GetVisibleRows = Count - 1' since there are that number of visible rows. NumRows, in Form_Load will be the 'real' number of visible rows.

    The second problem is to do with the last 2 'visible' rows.
    In Subroutine SetupCombo I a debug statement in thus
    Code:
        With msh
       
            .Row = Row   ' Position ourselves at the row where the combobox needs to be displayed
        
            ' Get the position for the first cell in that row
            
            With .Container
                sngL = .ScaleX(msh.CellLeft, vbTwips, .ScaleMode)
                sngT = .ScaleY(msh.CellTop, vbTwips, .ScaleMode)
                sngW = .ScaleX(msh.CellWidth, vbTwips, .ScaleMode)
                sngH = .ScaleY(msh.CellHeight, vbTwips, .ScaleMode)
            End With
            Debug.Print sngL, sngT, sngW, sngH, cbo.Text
        End With
    Having changed the number of rows to 20 this is the result of the last few:
    Code:
     45            3510          1680          300          Text 12
     45            3825          1680          300          Text 13
     45            4140          1680          300          Text 14
     45            4455          1680          300          Text 15
     45            4455          1680          300          Text 16
    as you can see, the last 2 have identical positions which implies that statements such as msh.Container.ScaleX...... etc are not telling you the truth or you're still looping once too often. I haven't gone completely through the logic but perhaps as you're so close to it you can see what to do.

  14. #14

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Create an ComboBox inside a Listview

    Yes, I know about the identical .CellTop positions. That is how I can tell if .RowIsVisible is telling me about a partial view of the last row, I adjust for that. The problem is when I want to use the information to operate on that last cell. The lie that it tell me is that basically it is the same as the previous row. Which of course is incorrect. I am looking for a work-a-round to that issue.

    The "Easy One:" you talk about is already correct. I want the routine to return the actual number of complete rows visible.

  15. #15

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Create an ComboBox inside a Listview

    Here is the working code... Floating and Scrolling...

    Thanks for all the input.
    Attached Files Attached Files

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