列表框中的正确格式

Proper Formatting in a listbox

我正在尝试格式化我的列表框,以便它在使用时看起来整洁。

我想在我的数字中添加美元符号,并将它们左对齐。任何帮助,将不胜感激。他们现在看起来真的很草率。

    Dim salesTotal As Double
    customerListBox.Items.Add("Customer: " & "                     " & "Total Sale: ")
    For Each record As DataRow In Me._442_Project_Part_2DataSet.Customers
        salesTotal += Double.Parse(CStr(record.Item("YTDSales")))
        customerListBox.Items.Add((CStr(record.Item("CustomerName"))) & "           " & (CStr(record.Item("YTDSales"))))
        customerListBox.Items.Add("------------------------------------------------")
    Next

首先,ListBox 并不意味着易于定制。

要回答您的问题 I want to add dollar signs to my numbers, and left align them,您需要使用 String.PadLeft 函数。

customerListBox.Items.Add((CStr(record.Item("CustomerName"))) & " : $" & (CStr(record.Item("YTDSales"))).PadLeft(8))

注意:我在这个例子中添加了8个空格。它可能会有所不同,具体取决于您拥有的数字。我还在 CustomerName 和 Sales 之间添加了一个冒号和美元符号。