Vb.net VB:ListView在添加太多项目时不自动创建滚动条?

Vb.net VB:ListView在添加太多项目时不自动创建滚动条?,vb.net,listview,scrollbar,Vb.net,Listview,Scrollbar,我目前在一个表单中包含一个ListView,然后通过代码隐藏将按钮添加到此ListView。除了列表中添加了太多的项目而没有创建垂直滚动条之外,其他一切都运行得非常好?我可以简单地添加任意多个按钮,而不必创建一个?下面是将按钮添加到列表中的代码: Dim x As Integer = 0 Dim btnCount As Integer = -1 Dim totalButtons As List(Of Button) = New List(Of Bu

我目前在一个表单中包含一个ListView,然后通过代码隐藏将按钮添加到此ListView。除了列表中添加了太多的项目而没有创建垂直滚动条之外,其他一切都运行得非常好?我可以简单地添加任意多个按钮,而不必创建一个?下面是将按钮添加到列表中的代码:

        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
            'Create 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)

任何帮助都将不胜感激!我确实设置了Scrollable=true,请尝试为ListView定义一个高度。

我想我现在可以回答我自己的问题了。添加到ListView的按钮控件没有添加到视图的集合中,而是直接添加到控件中。这就是我遇到困难的地方。我假设只有当视图的集合子项增长超过某个点时,才会出现滚动条,因为每次添加a按钮时,我只是向集合中添加了一些东西,它就给了我滚动条!显然,我不喜欢这个解决方案,只是简单地使用了DataGridView,因为预构建按钮列。

标题是TextView,但我想你指的是ListView。我确实在以前的方法中静态定义了高度。此后,我将范围缩小到向视图中添加控件,而不是向集合中添加项。谢谢,是的。后来我搬到了DataGridView,让我的生活更轻松。甚至不需要具有cellClick功能的按钮。感谢您的尝试,非常感谢。我已经缩小了范围,将控件添加到视图中,而不是将项目添加到集合中。正在尝试向集合中添加按钮,以查看是否可能。