Combobox in a listview subitem column

Posted on 2004-10-11
Medium Priority
Last Modified: 2008-01-09
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.


Question by:Bobeo

Expert Comment

ID: 12276466
You should have combo box on form, and fill it when user select listview item and move it to the subitem position

Expert Comment

ID: 12276508

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

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

Accepted Solution

Shauli earned 2000 total points
ID: 12277778
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)
End Sub


Author Comment

ID: 12296299
That should do the trick, thanks Shauli

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As a person who answers a lot of questions, I often see code that could be simplified, made easier to read, and perhaps most importantly made easier to maintain if the code was modified to use the Select Case statement. This article explains how to…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question