Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one make a horizontal listbox in .NET

I am working on porting a VB6 application to .NET and one of the desired UI elements is a horizontal listbox. I can't seem to figure out how to replicate this in .NET.

  1. Can this be done with basic winforms?

  2. How would you replicate this?

Sample:
alt text

The VB6 code that will replicate the above image:

Private Sub Form_Load()
    lst_horizontal(1).FontSize = 6
    Dim iMaxChoices As Integer
    iMaxChoices = 10
    For i = 1 To iMaxChoices
        lst_horizontal(1).AddItem (" " + CStr(i))
    Next i
End Sub

Private Sub lst_horizontal_Click(Index As Integer)
    Dim iMaxChoices As Integer
    iMaxChoices = 10

    For i = 0 To iMaxChoices - 1

        If lst_horizontal(1).Selected(i) Then
            Debug.Print ("Item " + CStr(i + 1) + " selected")
        End If

    Next i

Weasel words: I can figure out how to replicate this in Silverlight/XAML, but this app can't be done in that fashion.

like image 366
Tangurena Avatar asked Jan 21 '11 20:01

Tangurena


2 Answers

I would suggest the ListView with LargIcon for View property, It might be a good and ready solution for your case.

alt text

Good luck!

like image 143
Homam Avatar answered Oct 04 '22 21:10

Homam


This is supported in Winforms as well. Set the MultiColumn property to True, the ColumnWidth property to, say, 15. Producing:

enter image description here

like image 38
Hans Passant Avatar answered Oct 04 '22 22:10

Hans Passant