Solved

Combobox in a listview subitem column

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 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…
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…

803 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