2015-04-30 31 views
1

我想格式化我的列表框,以便它在使用時看起來很整潔。在列表框中正確格式

我想爲我的號碼添加美元符號,並將它們對齊。任何幫助,將不勝感激。他們目前看起來很sl。。

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 

回答

2

首先,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之間添加了冒號和美元符號。

+0

這實際上工作得很好。謝謝! – zalemam