组合框在vb

时间:2016-04-03 14:47:59

标签: vb.net winforms

我正在使用一个组合框,里面有20个数字(从1到20),表示一个日期和时间文本框,可以在另一个弹出窗体中显示。

例如,如果选择4,则可以看到4个日期和时间框。

问题:

最多可以看到9个日期和时间框,但从10到20我只能看到一个日期和时间框。我无法解决这个问题,我们将不胜感激。

这是我的代码:

Private Sub payno__SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles payno.SelectedIndexChanged

    Dim selectedIndex As Integer
    selectedIndex = payno.SelectedItem

    Dim selectedItem As Object

    selectedItem = payno.SelectedItem

    MessageBox.Show("Selected Item Text: " & selectedItem.ToString() & Microsoft.VisualBasic.Constants.vbCrLf &
                    "Index: " & selectedIndex.ToString())




    If payno.Text.Trim.Contains("1") = True Then
        paytime.DateTimePicker1.Visible = True
        paytime.DateTimePicker2.Visible = False
        paytime.DateTimePicker3.Visible = False
        paytime.DateTimePicker4.Visible = False
        paytime.DateTimePicker5.Visible = False
        paytime.DateTimePicker6.Visible = False
        paytime.DateTimePicker7.Visible = False
        paytime.DateTimePicker8.Visible = False
        paytime.DateTimePicker9.Visible = False
        paytime.DateTimePicker10.Visible = False
        paytime.DateTimePicker11.Visible = False
        paytime.DateTimePicker12.Visible = False
        paytime.DateTimePicker13.Visible = False
        paytime.DateTimePicker14.Visible = False
        paytime.DateTimePicker15.Visible = False
        paytime.DateTimePicker16.Visible = False
        paytime.DateTimePicker17.Visible = False
        paytime.DateTimePicker18.Visible = False
        paytime.DateTimePicker19.Visible = False
        paytime.DateTimePicker20.Visible = False




        ElseIf payno.Text.Trim.Contains("2") = True Then
        paytime.DateTimePicker1.Visible = True
        paytime.DateTimePicker2.Visible = True
        paytime.DateTimePicker3.Visible = False
        paytime.DateTimePicker4.Visible = False
        paytime.DateTimePicker5.Visible = False
        paytime.DateTimePicker6.Visible = False
        paytime.DateTimePicker7.Visible = False
        paytime.DateTimePicker8.Visible = False
        paytime.DateTimePicker9.Visible = False
        paytime.DateTimePicker10.Visible = False
        paytime.DateTimePicker11.Visible = False
        paytime.DateTimePicker12.Visible = False
        paytime.DateTimePicker13.Visible = False
        paytime.DateTimePicker14.Visible = False
        paytime.DateTimePicker15.Visible = False
        paytime.DateTimePicker16.Visible = False
        paytime.DateTimePicker17.Visible = False
        paytime.DateTimePicker18.Visible = False
        paytime.DateTimePicker19.Visible = False
        paytime.DateTimePicker20.Visible = False

        and so on until 20 ...

2 个答案:

答案 0 :(得分:1)

无论你写的是什么逻辑,它都是正确的,它必须有效。但它不是最好的编码实践。但是如果你想修改相同的代码。使用

之类的条件

如果payno.Text.trim =" 1"然后

Elseif payno.Text.trim =" 2"然后

.......

如果payno.Text.trim =" 10"那么

Elseif payno.Text.trim =" 11"然后

1.但是请将所有日期保存在一个面板中 2.使面板停靠在顶部 3.将滚动设置为true到面板

如果弹出窗体的高度低于日期控件的顶部,也可能无法显示。

希望有所帮助

答案 1 :(得分:0)

未经测试但是这样:

Dim x as Integer
While (x <= Integer.Parse(payno.Text.Trim))
   Select (x)
      Case 1
         paytime.DateTimePicker1.Visible = True
      Case 2
         paytime.DateTimePicker2.Visible = True
.....



   End Select
End While