Solved

Combobox in a listview subitem column

Posted on 2004-10-11
4
9,782 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
ID: 12276466
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
ID: 12276508
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
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)
    Combo1.SetFocus
End Sub

S
0
 
LVL 3

Author Comment

by:Bobeo
ID: 12296299
That should do the trick, thanks Shauli
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
using Access 8 75
Access 2013 combo box not working 3 51
vb6 connector to mongodb 2 120
MS Access 03, TransferText, decimal places 8 78
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

860 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