UI的第10个元素不会出现在UI上

时间:2014-03-23 21:20:03

标签: arrays vb.net panel vb.net-2010

我使用以下过程将一个继承Panel的类的4个元素(11个元素长)添加到UI中:

Private Sub AddBowlers()
    Dim count As Integer = 0
    For i = 0 To _sortList.ToArray.Length - 1
        If CheckSelectedPlayer(_sortList(i).PlayerID) Then       'if the player has not already been selected
            count += 1
            _team(count + 6) = New PickTeamLine(_sortList(i))    'initialise a new line, passing it the current bowler in the team list
            AddHandler _team(count + 6).RemoveButtonClicked, AddressOf RemovePlayer   'add the remove button's event handler
            _team(count + 6).SetBounds(3 * INDENT, INDENT + GAP * (count + 6),
                ViewLine.DefaultWidth, ViewLine.DefaultHeight) 'set the position/size of the current line
            Controls.Add(_team(i + 6))                                                'add the current line to the UI's list of controls
            _team(count + 6).Tag = count + 6                                          'assign a value in the line to store the line number it is on
            MsgBox(_team(count + 6).ActivePlayer.Surname)
        End If

        If count = 4 Then 'if 4 bowlers are selected then exit
            Exit Sub
        End If
    Next
End Sub

_team数组中的前7个对象可以通过前面的过程正确添加,但是在运行时,不会添加数组中的第10个元素,尽管它被正确地分配给_team数组(当count = 3时),如MsgBox显示正确的姓氏。

有没有特别的理由为什么只有第10个元素没有添加到用户界面,即使1-9和11被添加到正确的位置?

此处的参考是在添加_team数组后表单的样子。 (_team的每个元素都包含一个玩家的名字,bat avg,bowl avg及其删除按钮)

http://puu.sh/7GN2l.png

1 个答案:

答案 0 :(得分:0)

您可以像这样创建新的PickTeamLine:

_team(count + 6) = New PickTeamLine(_sortList(i))

然后在添加控件时,使用i而不是count

Controls.Add(_team(i + 6))