【问题标题】:converting listbox to my format将列表框转换为我的格式
【发布时间】:2014-01-28 17:45:27
【问题描述】:

我正在尝试格式化列表框输出以符合我的格式化程序。它只是列出了它们。有什么想法吗?

Private Sub Formatter_Click(sender As Object, e As EventArgs) Handles Formatter.Click
    Dim formatter As String = CStr("{0,-7} {1,6:C2} {3,5}")
    Dim name As String
    name = (First.Text) + (Second.Text)
    Dim x, y As Integer
    x = ((InputBox("Enter a Number")))
    y = (InputBox("Enter another Number"))
    With Values.Items
        .Add(x)
        .Add(y)
        .Add(name)
    End With

【问题讨论】:

    标签: asp.net .net vb.net listbox


    【解决方案1】:

    您需要使用String.Format 来格式化这些值并将它们连接成一个字符串。然后,您可以在每个项目中仅致电 ListBox.Items.Add 一次。像这样:

    Values.Add(String.Format(formatter, name, x, y))
    

    我不确定您打算输出这些值的顺序,所以这只是一个示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-13
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多