开发者

VB: ListView not auto-creating scrollbar when too many items added?

I'm currently housing a ListView on a single form, and then adding buttons to this ListView via code-behind. Everything works wonderfully except the fact that when there are too many items added to the list it doesn't create a vertical scroll bar? I can simply add as many buttons as I want to it without it creating one? Here's the code that adds the button to the list:

        Dim x As Integer = 0
        Dim btnCount As Integer = -1
        Dim totalButtons As List(Of Button) = New List(Of Button)
        Dim mItems As ListView.ListViewItemCollection =
                New ListView.ListViewItemCollection(lstViewEditor)

        For x = 0 To 14
            'Cre开发者_如何学Cate Button
            Dim button As Button = New Button
            button.Text = "0"
            button.BackgroundImageLayout = ImageLayout.Center
            button.BackColor = Color.WhiteSmoke
            button.Width = ((Me.lstViewEditor.Width - 10) / 15)
            button.Height = button.Width
            button.Location = New Point(x * (button.Width), 0)

            'If start
            If (Me.lstViewEditor.Controls.Count <= 14) Then
                button.Text = "2"
                button.BackColor = Color.Azure
            End If

            'Add To View
            'Me.Controls.Add(button)
            totalButtons.Add(button)

            btnCount = totalButtons.Count - 1
            AddHandler button.Click, AddressOf totalButtonHandler
        Next
        lstViewEditor.Controls.AddRange(totalButtons.ToArray)

Any help will be much appreciated! I have indeed set Scrollable = true


Try defining a height for the ListView.


I suppose I could answer my own question at this point. The Button (controls) being added to the ListView were not being added to the View's collection, but instead simply added directly to the control. This is where I was having difficulty. I'm assuming that only when the collection children for the view grows past a certain point you'll get scrollbars because I simply added a few things to the collection each time I added the a Button and it gave me the bars! Didn't like this solution so obviously simply used a DataGridView for simplicity because of the pre-build ButtonColumn.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜