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.
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
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.
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...
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.
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.
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.