Click here to Skip to main content
15,891,033 members
Articles / Programming Languages / Visual Basic
Tip/Trick

.NET dropdown in listview item / subitem... etc.

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
25 Jan 2012CPOL 35.6K   9
Quick and easy way to add dropdown functionality to the listview.

I had the need for a dropdown in my listview... did a bit of research, I did find some references, but all of it was pages of code with really complicated methods. I played around a bit, and found that the listview (at least on .NET 4), gives us more than enough to work with to easily achieve this.


Here ya go...


VB
Private Sub ListView1_DoubleClick(ByVal sender As Object, _
              ByVal e As System.EventArgs) Handles ListView1.DoubleClick
    ListView1.SelectedItems(0).BeginEdit()
    drop_combo()
End Sub

Private Sub drop_combo()
    Dim rect As New Rectangle
    rect = ListView1.SelectedItems(0).GetBounds(ItemBoundsPortion.Label)
    cbo_test.Visible = True
    cbo_test.Parent = ListView1
    cbo_test.Left = rect.Left - 2  'Normal left is just a little bit off, can see the abck label sticking out...
    cbo_test.Top = rect.Top
    cbo_test.Width = rect.Width
End Sub

Private Sub hide_combo()
    cbo_test.Visible = False
End Sub

Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, _
              ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
    hide_combo()
End Sub

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
South Africa South Africa
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionDo you know how to make the item user click in the combo box into the list view? Pin
Member 120978181-Nov-15 2:52
Member 120978181-Nov-15 2:52 
GeneralRe: No prob. Pin
Louis van Tonder1-Feb-12 2:08
Louis van Tonder1-Feb-12 2:08 
GeneralRe: Please do share if you get something going on ASP. I would b... Pin
Louis van Tonder1-Feb-12 2:09
Louis van Tonder1-Feb-12 2:09 
GeneralRe: Thank you for your reply. The events exposed by the ListView... Pin
djanardhanan31-Jan-12 4:24
djanardhanan31-Jan-12 4:24 
GeneralCan you please tell if you are doing this on windows or web ... Pin
djanardhanan31-Jan-12 3:34
djanardhanan31-Jan-12 3:34 
GeneralRe: Windows, but somethign similar should work for web? Not sure... Pin
Louis van Tonder31-Jan-12 4:23
Louis van Tonder31-Jan-12 4:23 
GeneralHI, sorry, did not apste all of the code. cbo_test is a dum... Pin
Louis van Tonder29-Jan-12 20:36
Louis van Tonder29-Jan-12 20:36 
GeneralRe: Thank you for your reply~~~ Pin
tdyso_zmh1-Feb-12 1:05
tdyso_zmh1-Feb-12 1:05 
GeneralDear Louis, I am very interested in your code.But where is c... Pin
tdyso_zmh29-Jan-12 14:47
tdyso_zmh29-Jan-12 14:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.