Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

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

0.00/5 (No votes)
25 Jan 2012 1  
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here