Click here to Skip to main content
15,918,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am binding values to list box but stirng not showing in proper format.

ex my strings like

abc 10
abcd 20
asdfas 30

I made fixed length to first string that is 30 using pading

C#
str1.PadRight(30) + str2.PadRight(2)

then also I am getting values like that

abc 10
abcd 20
asdfas 30

Plese suggest how can I put same space between string
Posted
Updated 26-Jun-12 23:51pm
v2
Comments
Herman<T>.Instance 27-Jun-12 5:51am    
Is that Padding done before Binding?
to.areeb 27-Jun-12 5:55am    
Yes just before
Herman<T>.Instance 27-Jun-12 5:58am    
can you show that code? Some lines before and after the Pad's
to.areeb 27-Jun-12 6:00am    
sItem = strName.Trim.PadRight(30) & Space(3) & .StrCode.Trim.PadRight(3)

listbox1.items.add(sItem)

strName and StrCode coming from database
Herman<T>.Instance 27-Jun-12 6:27am    
tried something like:

sItem = string.Format("{0} {1}", strName.PadRight(30), StrCode.PadRight(3));

if it still gives the same error it might be possiblethat the Items.Add() does a TRIM() in the background!

1 solution

IF you want to digit below the other in same potion along x-axis then first calulate length of first string and using padding.padsding value derive by certain value - length of string
eg

str1.PadRight(30-str1.length)

I hope it will work
 
Share this answer
 
Comments
to.areeb 27-Jun-12 6:18am    
Same Problem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900