473,715 Members | 6,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Format Data Column

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.0 1|-3147

The first two columns are pretty much text column, but subsequent columns
1-12 are numerical. I'm trying to get the thousand separator to work. Any
ideas?

--
Hutty
Nov 18 '05 #1
6 3836
Hi,

It is not clear what you need to show, but the following format string:

#,#.00

will produce the following:

51300.01 -> 51,300.01
123123123 -> 123,123,123.00
-3147 -> -3,147.00

If you don't need to show zeros after the decimal point and you know that
there are at most 5 digits after the decimal point use the following:

#,#.#####

Read more about custom numeric format strings:

http://msdn.microsoft.com/library/en...matstrings.asp

Hope this helps
Martin
"Hutty" <Hu***@discussi ons.microsoft.c om> wrote in message
news:A0******** *************** ***********@mic rosoft.com...
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.0 1|-3147

The first two columns are pretty much text column, but subsequent columns
1-12 are numerical. I'm trying to get the thousand separator to work. Any ideas?

--
Hutty

Nov 18 '05 #2
I've read the article referenced above along with others, but can't get the
correct coding to format the column in the datagrid. Here's my latest
attempt in trying to format column 3 of the datagrid.

DataGrid1.Colum ns(3).ToString. Format("#,##0," )

"Martin Dechev" wrote:
Hi,

It is not clear what you need to show, but the following format string:

#,#.00

will produce the following:

51300.01 -> 51,300.01
123123123 -> 123,123,123.00
-3147 -> -3,147.00

If you don't need to show zeros after the decimal point and you know that
there are at most 5 digits after the decimal point use the following:

#,#.#####

Read more about custom numeric format strings:

http://msdn.microsoft.com/library/en...matstrings.asp

Hope this helps
Martin
"Hutty" <Hu***@discussi ons.microsoft.c om> wrote in message
news:A0******** *************** ***********@mic rosoft.com...
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.0 1|-3147

The first two columns are pretty much text column, but subsequent columns
1-12 are numerical. I'm trying to get the thousand separator to work.

Any
ideas?

--
Hutty


Nov 18 '05 #3
Hi,

If the grid is with AutoGenerateCol umns=true then you are in trouble - you
will have to format the DataSource. e.g: If it is a DataTable you will need
to create a new DataTable with the same number of columns all of type
string. Then loop through the rows and columns of the original one and store
the result of ToString(format ) on each value in the corresponding cell of
the new DataTable. Then bind the grid with the new datatable.

Otherwise:
For BoundColumn's use the property DataFormatStrin g
For HyperlinkColumn 's and ButtonColumn's use the property
DataTextFormatS tring
For TemplateColumn' s - inside the ItemTemplate use the overload of
DataBinder.Eval that takes the format as parameter

e.g:
[C#]
(grid.Columns[0] as BoundColumn).Da taFormatString = "{0:#,#.00} ";
[VB]
DirectCast(grid .Columns(0), BoundColumn).Da taFormatString = "{0:#,#.00} "

Just make sure you set the formats before the call to DataBind() on the
grid.

Greetings
Martin
"Hutty" <Hu***@discussi ons.microsoft.c om> wrote in message
news:D5******** *************** ***********@mic rosoft.com...
I've read the article referenced above along with others, but can't get the correct coding to format the column in the datagrid. Here's my latest
attempt in trying to format column 3 of the datagrid.

DataGrid1.Colum ns(3).ToString. Format("#,##0," )

"Martin Dechev" wrote:
Hi,

It is not clear what you need to show, but the following format string:

#,#.00

will produce the following:

51300.01 -> 51,300.01
123123123 -> 123,123,123.00
-3147 -> -3,147.00

If you don't need to show zeros after the decimal point and you know that there are at most 5 digits after the decimal point use the following:

#,#.#####

Read more about custom numeric format strings:

http://msdn.microsoft.com/library/en...matstrings.asp
Hope this helps
Martin
"Hutty" <Hu***@discussi ons.microsoft.c om> wrote in message
news:A0******** *************** ***********@mic rosoft.com...
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.0 1|-3147

The first two columns are pretty much text column, but subsequent columns 1-12 are numerical. I'm trying to get the thousand separator to work.

Any
ideas?

--
Hutty


Nov 18 '05 #4
I'm sort of new to the coding. I do have the AutoGenerate set to TRUE. The
datagrid is assigned datasource at runtime. I inserted the DirectCast line
below and got an error stating index is out of range. Here's my code that
populates the grid.
Private Sub cmdOK_Click(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles cmdOK.Click
Dim DS As New System.Data.Dat aSet
Dim DT As New System.Data.Dat aTable
Dim MyCommand As System.Data.Ole Db.OleDbDataAda pter
Dim MyConnection As System.Data.Ole Db.OleDbConnect ion

MyConnection = New System.Data.Ole Db.OleDbConnect ion( _
"provider=Micro soft.Jet.OLEDB. 4.0; " & _
"data source=C:\Inetp ub\wwwroot\inte lis.MDB")

TextBox1.Text = DropDownList1.S electedItem.ToS tring
MyCommand = New System.Data.Ole Db.OleDbDataAda pter( _
"select * from " & ListBox1.Select edValue.ToStrin g & " where
Entity = '" & DropDownList1.S electedValue.To String & "'", MyConnection)

DS = New System.Data.Dat aSet
DS.Clear()

MyCommand.Fill( DS)

DT = DS.Tables(0)
' DataGrid1.DataM ember =
DataGrid1.DataS ource = DT

DirectCast(Data Grid1.Columns(3 ), BoundColumn).Da taFormatString
"{0:#,#.00} "

DataGrid1.DataB ind()
End Sub
"Martin Dechev" wrote:
Hi,

If the grid is with AutoGenerateCol umns=true then you are in trouble - you
will have to format the DataSource. e.g: If it is a DataTable you will need
to create a new DataTable with the same number of columns all of type
string. Then loop through the rows and columns of the original one and store
the result of ToString(format ) on each value in the corresponding cell of
the new DataTable. Then bind the grid with the new datatable.

Otherwise:
For BoundColumn's use the property DataFormatStrin g
For HyperlinkColumn 's and ButtonColumn's use the property
DataTextFormatS tring
For TemplateColumn' s - inside the ItemTemplate use the overload of
DataBinder.Eval that takes the format as parameter

e.g:
[C#]
(grid.Columns[0] as BoundColumn).Da taFormatString = "{0:#,#.00} ";
[VB]
DirectCast(grid .Columns(0), BoundColumn).Da taFormatString = "{0:#,#.00} "

Just make sure you set the formats before the call to DataBind() on the
grid.

Greetings
Martin
"Hutty" <Hu***@discussi ons.microsoft.c om> wrote in message
news:D5******** *************** ***********@mic rosoft.com...
I've read the article referenced above along with others, but can't get

the
correct coding to format the column in the datagrid. Here's my latest
attempt in trying to format column 3 of the datagrid.

DataGrid1.Colum ns(3).ToString. Format("#,##0," )

"Martin Dechev" wrote:
Hi,

It is not clear what you need to show, but the following format string:

#,#.00

will produce the following:

51300.01 -> 51,300.01
123123123 -> 123,123,123.00
-3147 -> -3,147.00

If you don't need to show zeros after the decimal point and you know that there are at most 5 digits after the decimal point use the following:

#,#.#####

Read more about custom numeric format strings:

http://msdn.microsoft.com/library/en...matstrings.asp
Hope this helps
Martin
"Hutty" <Hu***@discussi ons.microsoft.c om> wrote in message
news:A0******** *************** ***********@mic rosoft.com...
> 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.0 1|-3147
>
> The first two columns are pretty much text column, but subsequent columns > 1-12 are numerical. I'm trying to get the thousand separator to work.
Any
> ideas?
>
> --
> Hutty


Nov 18 '05 #5
Hutty - Simply format the data as you're populating the DataTable, and then
bind it to your DataGrid. The DataGrid column will then display the
formatted data instead of attempting to format the DataGrid column itself.

"Hutty" wrote:
I'm sort of new to the coding. I do have the AutoGenerate set to TRUE. The
datagrid is assigned datasource at runtime. I inserted the DirectCast line
below and got an error stating index is out of range. Here's my code that
populates the grid.
Private Sub cmdOK_Click(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles cmdOK.Click
Dim DS As New System.Data.Dat aSet
Dim DT As New System.Data.Dat aTable
Dim MyCommand As System.Data.Ole Db.OleDbDataAda pter
Dim MyConnection As System.Data.Ole Db.OleDbConnect ion

MyConnection = New System.Data.Ole Db.OleDbConnect ion( _
"provider=Micro soft.Jet.OLEDB. 4.0; " & _
"data source=C:\Inetp ub\wwwroot\inte lis.MDB")

TextBox1.Text = DropDownList1.S electedItem.ToS tring
MyCommand = New System.Data.Ole Db.OleDbDataAda pter( _
"select * from " & ListBox1.Select edValue.ToStrin g & " where
Entity = '" & DropDownList1.S electedValue.To String & "'", MyConnection)

DS = New System.Data.Dat aSet
DS.Clear()

MyCommand.Fill( DS)

DT = DS.Tables(0)
' DataGrid1.DataM ember =
DataGrid1.DataS ource = DT

DirectCast(Data Grid1.Columns(3 ), BoundColumn).Da taFormatString
"{0:#,#.00} "

DataGrid1.DataB ind()
End Sub
"Martin Dechev" wrote:
Hi,

If the grid is with AutoGenerateCol umns=true then you are in trouble - you
will have to format the DataSource. e.g: If it is a DataTable you will need
to create a new DataTable with the same number of columns all of type
string. Then loop through the rows and columns of the original one and store
the result of ToString(format ) on each value in the corresponding cell of
the new DataTable. Then bind the grid with the new datatable.

Otherwise:
For BoundColumn's use the property DataFormatStrin g
For HyperlinkColumn 's and ButtonColumn's use the property
DataTextFormatS tring
For TemplateColumn' s - inside the ItemTemplate use the overload of
DataBinder.Eval that takes the format as parameter

e.g:
[C#]
(grid.Columns[0] as BoundColumn).Da taFormatString = "{0:#,#.00} ";
[VB]
DirectCast(grid .Columns(0), BoundColumn).Da taFormatString = "{0:#,#.00} "

Just make sure you set the formats before the call to DataBind() on the
grid.

Greetings
Martin
"Hutty" <Hu***@discussi ons.microsoft.c om> wrote in message
news:D5******** *************** ***********@mic rosoft.com...
I've read the article referenced above along with others, but can't get

the
correct coding to format the column in the datagrid. Here's my latest
attempt in trying to format column 3 of the datagrid.

DataGrid1.Colum ns(3).ToString. Format("#,##0," )

"Martin Dechev" wrote:

> Hi,
>
> It is not clear what you need to show, but the following format string:
>
> #,#.00
>
> will produce the following:
>
> 51300.01 -> 51,300.01
> 123123123 -> 123,123,123.00
> -3147 -> -3,147.00
>
> If you don't need to show zeros after the decimal point and you know

that
> there are at most 5 digits after the decimal point use the following:
>
> #,#.#####
>
> Read more about custom numeric format strings:
>
>

http://msdn.microsoft.com/library/en...matstrings.asp
>
> Hope this helps
> Martin
> "Hutty" <Hu***@discussi ons.microsoft.c om> wrote in message
> news:A0******** *************** ***********@mic rosoft.com...
> > 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.0 1|-3147
> >
> > The first two columns are pretty much text column, but subsequent

columns
> > 1-12 are numerical. I'm trying to get the thousand separator to work.
> Any
> > ideas?
> >
> > --
> > Hutty
>
>
>


Nov 18 '05 #6
I hear what you're saying, but can't seemed to get the code correct.
However, I'm able to get it to work using the following code. But don't
think it's efficient for insert 4-5 lines for each of the 14 columns. There
has to be a more efficient way of doing it.

DataGrid1.AutoG enerateColumns = False
DataGrid1.DataS ource = Me.DataSet31
DataGrid1.DataM ember = "Jan 04"
DataGrid1.DataK eyField = "Jan 04"

Dim dgc_col As New BoundColumn
dgc_col.DataFie ld = "Jan 04"
dgc_col.HeaderT ext = "Jan 04"
dgc_col.DataFor matString = "{0:N0}"
DataGrid1.Colum ns.Add(dgc_col)

"mr killer" wrote:
Hutty - Simply format the data as you're populating the DataTable, and then
bind it to your DataGrid. The DataGrid column will then display the
formatted data instead of attempting to format the DataGrid column itself.

"Hutty" wrote:
I'm sort of new to the coding. I do have the AutoGenerate set to TRUE. The
datagrid is assigned datasource at runtime. I inserted the DirectCast line
below and got an error stating index is out of range. Here's my code that
populates the grid.
Private Sub cmdOK_Click(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles cmdOK.Click
Dim DS As New System.Data.Dat aSet
Dim DT As New System.Data.Dat aTable
Dim MyCommand As System.Data.Ole Db.OleDbDataAda pter
Dim MyConnection As System.Data.Ole Db.OleDbConnect ion

MyConnection = New System.Data.Ole Db.OleDbConnect ion( _
"provider=Micro soft.Jet.OLEDB. 4.0; " & _
"data source=C:\Inetp ub\wwwroot\inte lis.MDB")

TextBox1.Text = DropDownList1.S electedItem.ToS tring
MyCommand = New System.Data.Ole Db.OleDbDataAda pter( _
"select * from " & ListBox1.Select edValue.ToStrin g & " where
Entity = '" & DropDownList1.S electedValue.To String & "'", MyConnection)

DS = New System.Data.Dat aSet
DS.Clear()

MyCommand.Fill( DS)

DT = DS.Tables(0)
' DataGrid1.DataM ember =
DataGrid1.DataS ource = DT

DirectCast(Data Grid1.Columns(3 ), BoundColumn).Da taFormatString
"{0:#,#.00} "

DataGrid1.DataB ind()
End Sub
"Martin Dechev" wrote:
Hi,

If the grid is with AutoGenerateCol umns=true then you are in trouble - you
will have to format the DataSource. e.g: If it is a DataTable you will need
to create a new DataTable with the same number of columns all of type
string. Then loop through the rows and columns of the original one and store
the result of ToString(format ) on each value in the corresponding cell of
the new DataTable. Then bind the grid with the new datatable.

Otherwise:
For BoundColumn's use the property DataFormatStrin g
For HyperlinkColumn 's and ButtonColumn's use the property
DataTextFormatS tring
For TemplateColumn' s - inside the ItemTemplate use the overload of
DataBinder.Eval that takes the format as parameter

e.g:
[C#]
(grid.Columns[0] as BoundColumn).Da taFormatString = "{0:#,#.00} ";
[VB]
DirectCast(grid .Columns(0), BoundColumn).Da taFormatString = "{0:#,#.00} "

Just make sure you set the formats before the call to DataBind() on the
grid.

Greetings
Martin
"Hutty" <Hu***@discussi ons.microsoft.c om> wrote in message
news:D5******** *************** ***********@mic rosoft.com...
> I've read the article referenced above along with others, but can't get
the
> correct coding to format the column in the datagrid. Here's my latest
> attempt in trying to format column 3 of the datagrid.
>
> DataGrid1.Colum ns(3).ToString. Format("#,##0," )
>
> "Martin Dechev" wrote:
>
> > Hi,
> >
> > It is not clear what you need to show, but the following format string:
> >
> > #,#.00
> >
> > will produce the following:
> >
> > 51300.01 -> 51,300.01
> > 123123123 -> 123,123,123.00
> > -3147 -> -3,147.00
> >
> > If you don't need to show zeros after the decimal point and you know
that
> > there are at most 5 digits after the decimal point use the following:
> >
> > #,#.#####
> >
> > Read more about custom numeric format strings:
> >
> >
http://msdn.microsoft.com/library/en...matstrings.asp
> >
> > Hope this helps
> > Martin
> > "Hutty" <Hu***@discussi ons.microsoft.c om> wrote in message
> > news:A0******** *************** ***********@mic rosoft.com...
> > > 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.0 1|-3147
> > >
> > > The first two columns are pretty much text column, but subsequent
columns
> > > 1-12 are numerical. I'm trying to get the thousand separator to work.
> > Any
> > > ideas?
> > >
> > > --
> > > Hutty
> >
> >
> >

Nov 18 '05 #7

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

Similar topics

1
12222
by: noor | last post by:
Hi I have been working since 2 days to device a method to export sql table into csv format. I have tried using bcp with format option to keep the column names but I'm unable to transfer the file with column names. and also I'm having problems on columns having decimal data. Can any one suggest me how to automate data transfer(by using SP) and retaining column names. Thanks Noor
3
9953
by: Daniel M. | last post by:
I have a query that gets a string column containing a date, ex. 20040825. If I use the property builder to format the string to 08/25/2004 it does not work because it only accepts datetime columns. How can I convert or format the string. Could I add a new dataset/datatable column containing the value as I need it. Thanks.
1
2311
by: J.B | last post by:
I have a datagrid that will display different datasets, (it runs different sprocs based on a value in the querystring) but it will always return 6 columns. The 5th and 6th columns are always Date and Currency format, all others are strings. I'd like to build one datagrid to handle this datagrid dynamically. I have it working now, all except the formatting of the 5th (Date) and 6th (Currency) columns. Since the headers for those...
4
9627
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 '07-Mar-05' the expression {..:dd-MMM-yy} works OK Second question, does anyone know hwo to return a date from SQL server in the format '07-Mar-05', as this would be a workaround. At the moment I'm using CONVERT(varchar(12),columnname,6 ) to...
6
9713
by: Ted | last post by:
I used bcp to produce the apended format file. How can it be modified to recognize the quotes that surround the text fields and not insert the quotes along with the text? Invariably, the first four columns have text surrounded by quotes and are terminated by tabs. If the first column has "abc", only abc ought to be inserted into that field in the table. Thanks
3
4057
by: chandra.krothapalli | last post by:
Hi, I am writing a program to read database logs using db2Readlog/ db2ReadLogNoConn API. I am able to parse the data of "FIXED format data" and link them to appropriate columns for a given UPDATE/INSERT/DELETE. I am having difficulty in parsing the "Variable format data". In the log record I am not able find information about data length of each
5
8070
by: E.Bartosiewicz | last post by:
I have several files with data I would like to import into DB2, but I have timestamps set in a format, which DB2 can't catch - DD-MM-YYYY HH:MM:SS DB2 wants to get the year first. Is there a way I can say that my data is going to come in this format or do I need to convert it outside the database? -- Ewa
2
2143
by: Dhananjay | last post by:
Hi all , I have got problem when i am tring to exportGridview Data into Excel format. It is going into text format ,but what i want is if the field is number/currency then it should go into number/currency format itself .Data exported to excel are all exported as text. Export to excel should maintain the formatting like numbers and money should be numbers and money in excel .
8
2574
by: joemacbusiness | last post by:
Hi All, How do I format printed data in python? I could not find this in the Python Reference Manual: http://docs.python.org/ref/print.html Nor could I find it in Matloff's great tutorial: http://heather.cs.ucdavis.edu/~matloff/Python/PythonIntro.pdf For example, how do I turn this:
0
9340
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9196
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7973
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5967
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4477
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3175
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2539
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.