Solved

Combobox in a listview subitem column

Posted on 2004-10-11
4
9,673 Views
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.

Cheers

Bob
0
Comment
Question by:Bobeo
4 Comments
 
LVL 8

Expert Comment

by:mladenovicz
Comment Utility
You should have combo box on form, and fill it when user select listview item and move it to the subitem position
0
 

Expert Comment

by:MoOTottle
Comment Utility
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
 
LVL 19

Accepted Solution

by:
Shauli earned 500 total points
Comment Utility
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
 
LVL 3

Author Comment

by:Bobeo
Comment Utility
That should do the trick, thanks Shauli
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now