[RESOLVED] padding a listbox
Hi All,
I create entries in a listbox in the form:
Dim Newitem As ListItem
Newitem = New ListItem(String.Concat(Sor.SORCode, " - ", Sor.Description), Sor.ID)
lstBoxAssSors.Items.Add(Newitem)
My SORCode may be anywhere from 1 - 7 characters.
I want to be able to pad the characters with spaces or non-printable chars so that They line up as columns on the page.
Any ideas how I can do this as trying to pad with space's the contorl strips them.
# 1 Re: [RESOLVED] padding a listbox
Since the listbox is not directly capable, you can try cheating it.
1. You have to make sure that you are using a fixed width font, such as Courier New.
2. Count the number of characters in your longest string for the left column and add 5 or so more characters.
3. Now let's say that this number equals 18...now you just subtract 18 from the length of every other left column text to know exactly how many spaces to put in.
# 2 Re: [RESOLVED] padding a listbox
Hi,
It's the Character that I need to pad with that I'm having problems with since I cannot pad with space.
So what should I pad with to make my data line up?
# 4 Re: [RESOLVED] padding a listbox
No It doesn't help. Perhaps it's the way I'm doing it.
I have created this function:
Public Shared Function PadString(ByVal StringToPad As String, ByVal PadToLength As Integer, ByVal PadCharacter As String) As String
Dim padLength As Integer = PadToLength - StringToPad.Length
Dim i As Integer
Do Until i = padLength
StringToPad &= PadCharacter
i += 1
Loop
Return StringToPad
End Function
and now use it
Newitem = New ListItem(String.Concat(GuiHelper.PadString(Sor.SORCode, 7, " "), " - ", Sor.Description), Sor.ID)
It always pads with the literal except when I do
Newitem = New ListItem(String.Concat(GuiHelper.PadString(Sor.SORCode, 7, " "), " - ", Sor.Description), Sor.ID)
Then it just strips the space's
# 6 Re: [RESOLVED] padding a listbox
I changed my line to :
Newitem = New ListItem(String.Concat(GuiHelper.PadString(Sor.SORCode, 7, Server.HtmlDecode(" ")), " - ", Sor.Description), Sor.ID)
And it worked a treat.
Thnaks for your help.