473,394 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Format string in DataGrid

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
Oct 30 '06 #1
8 3738
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:
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
Oct 31 '06 #2
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.(^^;
Oct 31 '06 #3
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
Oct 31 '06 #4
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.(^^;

Oct 31 '06 #5
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:
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.(^^;
Oct 31 '06 #6
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
Oct 31 '06 #7
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.(^^;
Oct 31 '06 #8
Yes, I caught that on the first pass.

I used CULng in my app since a UPC/EAN is always an unsigned number.

Rick

"Yuichiro Ochifuji" <oc******@japan.interq.or.jpwrote in message
news:eU**************@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.(^^;

Oct 31 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tamlin | last post by:
Hi all, I'm getting a bug with the datagrid object. I've created one from scratch, bound it to a dataview with 2 int32 columns and formatted the output as currency. I've found that when you...
7
by: Eddy Soeparmin | last post by:
Hi, I need to display a DateTime field in 'mm/dd/yyyy' in a DataGrid.. On myGrid1 - Properties - Columns - myColumn1 - Text format string: I tried to put 'mm/dd/yyyy' in there and it displays...
10
by: ruca | last post by:
Hi I want to format some columns of my DataGrid control. Example, one of my fields of DataSet is a DATE field and in BD he is Ok, but when I show him in datagrid he comes with hours too. I...
6
by: Hutty | last post by:
I've looked around and have yet to find anything that would answer my question regarding formating a column in a datagrid. My grid looks like this as far as data" AMHQCON|51300.01|-3147 The...
4
by: yer darn tootin | last post by:
Does anyone know the sort expression for a column that's data has been returned in the format, eg '07 Jul 05'?? The sort expression {..:"dd mmm yy"} doesn't work ( if the column was returned as...
1
by: Julius Fenata | last post by:
Dear all, I need help to change my item-template value format... Here is my case, I have a datagrid, with 'SubjectPrice' field, and when the grid displayed, my 'SubjectPrice' field displayed...
5
by: Robin Tucker | last post by:
My database has a column for numeric data items. How can I use this number in the "format" command, such that for, say precision 2, I get numbers like 2011.01 or 2387.00 and for 4 I would get...
2
by: Derek Vincent | last post by:
What must I do to overcome a problem with my dates becoming formatted as "2/22/2525 12:00:00 AM" in the datagrid? I want to handle all dates as short string of format "2/22/2525." Otherwise when I...
2
by: Joel | last post by:
I'm trying to format the data from our database query that is being binded to a DataGrid. Basically an easy example to understand the problem is a field in the database uses 1's and 0's to show...
1
by: differentsri | last post by:
THIS IS AN ASP.NET 1.1 APPLICATION IAM TRYING TO UPDATE THE FIELD BUT I AM NOT ABLE TO UPDATE IT? CAN U TELL THE REASON ? IT IS GIVING THE FOLLOWING ERROR BELOW I HAVE ALSO GIVEN THE CODE OF...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.