Combobox in a listview subitem column

Hello Experts!

I'm developing some software that has a list of car parts, into which i need to specify how many hours the job will take.  it looks something like this

:: Part ::                               :: Hours ::
Bumper                                       5.2
Bonnet                                        10.5


What i need to do as have the hours in a combobox.  I am currently using a listview control but you cant add combos to the columns from what i am aware.  I'm looking for a component into which you can add combos into columns, like you can in an excel cell.

The alternative is to have the combos above the listview and apply the combo's text to the listview's subitem but that's not really what the client wants.

Would be willing to pay if needed too.

Any help would be appreciated.

Cheers

Bob
LVL 3
BobeoAsked:
Who is Participating?
 
ShauliConnect With a Mentor Commented:
The downside in the example below is that the listview row height is smaller than the combo height.


Option Explicit

Private Sub Combo1_Click()
ListView1.ListItems(ListView1.SelectedItem.Index).ListSubItems(1).Text = Combo1.Text
Combo1.Visible = False
End Sub

Private Sub Form_Load()
Dim myListItem As ListItem

ListView1.View = lvwReport
ListView1.GridLines = False
ListView1.FullRowSelect = False
ListView1.ColumnHeaders.Add , , "Part"
ListView1.ColumnHeaders.Add , , "Hours"
ListView1.ColumnHeaders(1).Width = ListView1.Width / 2
ListView1.ColumnHeaders(2).Width = ListView1.Width / 2

Set myListItem = ListView1.ListItems.Add(, , "Bumper")
    myListItem.SubItems(1) = "5.2"
Set myListItem = ListView1.ListItems.Add(, , "Bonnet")
    myListItem.SubItems(1) = "10.5"

Combo1.Visible = False
Combo1.AddItem "1"
Combo1.AddItem "3.6"
Combo1.AddItem "5.2"
Combo1.AddItem "10.5"
Combo1.AddItem "12.4"
End Sub

Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
Combo1.Visible = False
Combo1.Left = ListView1.ColumnHeaders(2).Left + 240
Combo1.Top = ListView1.Top + Item.Top + 40
    Combo1.Visible = True
    Combo1.Text = Item.ListSubItems(1).Text
    Combo1.SelStart = 0: Combo1.SelLength = Len(Item.ListSubItems(1).Text)
    Combo1.SetFocus
End Sub

S
0
 
mladenoviczCommented:
You should have combo box on form, and fill it when user select listview item and move it to the subitem position
0
 
MoOTottleCommented:
Bob,

If you make a "template" control and specify it as a control array, i.e. set the index to 0.

You can then load new copies of the controls at run time, using code similar to:

        Do Until objRS.EOF Or i = 10
                Load lblPart(i)
                lblPart(i).Top = lblPart(i - 1).Top + lblPart(i - 1).Height + x
                Load cmdInfo(i)
                cmbHours(i).Top = lblPart(i).Top
                lblPart(i).Visible = True
                cmbHours(i).Visible = True
            i = i + 1
            objRS.movenext
       loop

In my example,
objRS      -    is a recordset control,
i              -    and integer
x              - is the distance you wish to appear between the controls.
cmbHours - is a combo box control
lblPart      - is a label control

You can perhapse use the controls .tag property to store a unique indentifyer to help you save the users output.
0
 
BobeoAuthor Commented:
That should do the trick, thanks Shauli
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.