|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Format string in DataGridVB.Net 2005
I have a non-bound datagridview that I fill with a column that contains a UPC number (as a string). I want the display format to be like this: 0 12345 67890 1. I have tried setting the format at design time to "# ##### ##### #" and also in the cell formatting event with: e.Value = Format(e.Value,"# ##### ##### #"). Neither works. How do I set this? Rick Probably not the best, but you could just parse the string yourself and
insert the spaces where needed. Something like: e.Value = e.Value.SubString(0,1) & " " & e.Value.Substring(1, 5) & " " & e.Value.Substring(6, 5) & " " & e.Value.Substring(11, 1) Thanks, Seth Rowe Rick wrote: Show quoteHide quote > VB.Net 2005 > > I have a non-bound datagridview that I fill with a column that contains a > UPC number (as a string). > > I want the display format to be like this: 0 12345 67890 1. > > I have tried setting the format at design time to "# ##### ##### #" and also > in the cell formatting event with: > e.Value = Format(e.Value,"# ##### ##### #"). > > Neither works. How do I set this? > > Rick Hi,
e.Value = Format(CInt(e.Value), "0 00000 00000 0") However, the row of a new addition is influenced in this method, too. -- Yuichiro Ochifuji JAPAN I am not good at English.(^^; Thank you Seth and Yuichiro,
It seems I will have to parse the string and add my spaces manually like Seth suggests. The solution from Yuichiro will not work becuase many UPC strings start with "0" i.e. 0 12345 23456. If I convert this to integer I loose the first "0" so the formatted string would be "12345 23456" and not "0 12345 23456" Rick Hi,Rick
> The solution from Yuichiro will not work becuase many UPC strings start In my way, it is not "# ##### ##### #", but "0 00000 00000 0".> with "0" i.e. 0 12345 23456. If I convert this to integer I loose the > first "0" so the formatted string would be "12345 23456" and not "0 12345 > 23456" "0" are sure to remain. -- Yuichiro Ochifuji JAPAN I am not good at English.(^^; Yes, thank you Yuichrio
That does work. I think I tried the # ###### before and lost the "0", but with your method it is always there. Rick When I run Yuichiro's sample I don't lose the leading zero, maybe you
typed it wrong? Also, you might note that my code is almost twice as fast because it avoids the using an integer conversion (although we're talking nanoseconds here - I had to loop through each method 1,000,000 times to get significant results). Also, if you use Yuichiro's code you might need to use CLng instead of CInt to prevent the possible overflow issue when you convert the string. Thanks, Seth Rowe Yuichiro Ochifuji wrote: Show quoteHide quote > Hi,Rick > > > The solution from Yuichiro will not work becuase many UPC strings start > > with "0" i.e. 0 12345 23456. If I convert this to integer I loose the > > first "0" so the formatted string would be "12345 23456" and not "0 12345 > > 23456" > > In my way, it is not "# ##### ##### #", but "0 00000 00000 0". > "0" are sure to remain. > > > -- > Yuichiro Ochifuji > JAPAN > I am not good at English.(^^; Hi,Seth
>Also, if you use Yuichiro's code you might Oh,I blundered. > need to use CLng instead of CInt to prevent the possible overflow issue > when you convert the string. Integer is from -2,147,483,647 to 2,147,483,647. Thanks. -- Yuichiro Ochifuji JAPAN I am not good at English.(^^; Yes, I caught that on the first pass.
I used CULng in my app since a UPC/EAN is always an unsigned number. Rick Show quoteHide quote "Yuichiro Ochifuji" <ochif***@japan.interq.or.jp> wrote in message news:eUsSbjP$GHA.1500@TK2MSFTNGP05.phx.gbl... > Hi,Seth > >>Also, if you use Yuichiro's code you might >> need to use CLng instead of CInt to prevent the possible overflow issue >> when you convert the string. > > Oh,I blundered. Integer is from -2,147,483,647 to 2,147,483,647. > > Thanks. > > > -- > Yuichiro Ochifuji > JAPAN > I am not good at English.(^^;
IsNumeric question
Access dynamic controls by name? Multiple Component Classes How to turn off Managed Debugging Assistant in VB.NET (2005) Messages Did Mabry Software Tank! OT-develing on several machines Replacing Double quotes with TWO Single Quotes Multiple TcpListeners on the same IP address Windows Service not starting automatically |
|||||||||||||||||||||||