×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

insert combobox in listview column

insert combobox in listview column

insert combobox in listview column

(OP)
Possible to call a combobox when i click on a listsubitem of column 3.
example,...

click on cell 4 of column 3, appear a combobox, with same width of cell, select value, click on, save value of combobox in current cell, hide combobox...

RE: insert combobox in listview column

Not simply,

The most elegant way to do this would be via OwnerDraw, which we hjave previoulsy illustrated in this forum for you. The only other way is pretty much to fake it by calculating the location of the bounding box of the listsubitem, and moving the combobox over it. But limitations of the listview control (and of the VB6 combo box) make even this a pain. here's an illustrative example of the idea - but I've knocked this together in about 20 mins, and it is NOT production code, and certainly does not deal properly with all conditions (e.g, if you have hidden any columns, or cloick where there is no column, or in a column header).

You'll need a form (Foprm1) with a Listview (ListView1) and a Combobox (Combo1):

CODE

Option Explicit
Public mySubitem As ListSubItem

Private Sub Form_Load()
    Dim itmX As ListItem   
    
    ' Set up a l of items with subitems
    Set itmX = ListView1.ListItems.Add(, , "hello")
    itmX.ListSubItems.Add , , "just"
    itmX.ListSubItems.Add , , "testing"
    
    Set itmX = ListView1.ListItems.Add(, , "goodbye")
    itmX.ListSubItems.Add , , "more"
    itmX.ListSubItems.Add , , "stuff"
    
    ' Now set up combobox - make sure it uses same font as listview to try and ensure similar heights,
    ' as neither the listview's item height, nor the combobox height can be directly set; they are reliant on the currently selected font
    Set Combo1.Font = ListView1.Font
    Combo1.AddItem "tell"
    Combo1.AddItem "me"
    Combo1.Visible = False
End Sub

Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    Dim lp As Long
    Dim myitem As ListItem
    
    lp = 1
    Do Until x > ListView1.ColumnHeaders(lp).Left And x < ListView1.ColumnHeaders(lp).Left + ListView1.ColumnHeaders(lp).Width
        lp = lp + 1
    Loop

    Set myitem = ListView1.HitTest(30, y)
    If Not myitem Is Nothing And lp > 1 Then
        Form1.Combo1.Move ListView1.Left + ListView1.ColumnHeaders(lp).Left + 15, ListView1.Top + myitem.Top '
        Form1.Combo1.Width = ListView1.ColumnHeaders(lp).Width
        Set mySubitem = myitem.ListSubItems(lp - 1)
        Combo1.Visible = True
    End If
End Sub 

RE: insert combobox in listview column

(OP)
STRONGM!!!!
The code is exactlly wath i need!
Tks as usual.

note:
i have set mySubitem As ListSubItem, correct?

I have option explicit, in the head of modulesmile

and i can set the hight of combobox?

RE: insert combobox in listview column

>and i can set the hight of combobox?

' Now set up combobox - make sure it uses same font as listview to try and ensure similar heights,
' neither the listview's item height, nor the combobox height can be directly set; they are reliant on the currently selected font

RE: insert combobox in listview column

(OP)
Strongm,
i have used you code, about combobox and listview. work.

But only a prob...
when i scroll the vertical bar of listview the combo remain locked to the last position and dont scroll together the rows!!!!

RE: insert combobox in listview column

>But only a prob...

1) Not a requirement you originally mentioned
2) I warned that I had not provided prodcution code, not a complete code solution solutions for you here

But is does mean you already have all the code you need to position the combobox (basically the following two lines)

CODE -->

Form1.Combo1.Move ListView1.Left + ListView1.ColumnHeaders(lp).Left + 15, ListView1.Top + myitem.Top '
Form1.Combo1.Width = ListView1.ColumnHeaders(lp).Width 

So now 'all' you need to do is subclass the listview, and respond to scroll messages in order to position the combo correctly. I suggest you download and examine the example code found here for this.

RE: insert combobox in listview column

(OP)
TKS strongm

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close