Datagrid Column Format

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the following VB.Net code which displays a 2-digit value from the
database. How do I format this column display in a 5-digit format (00012)?


oTextCol = New DataGridTextBoxColumn
oGridStyle.MappingName = "MyMapping"
oTextCol.MappingName = "MyData"
oTextCol.HeaderText = "My Data"
oTextCol.Width = 120
oGridStyle.GridColumnStyles.Add(oTextCol)
 
oTextCol.Format = "00000"


Now if someone can tell me how to represent negative numbers
with parenthesis instead of a minus sign, I'd be delighted :)
 
Well, I guess if the column type is text you could iterate through the
datasource after populating it and for each row do something like (C# syntax)

string sOrig = "12", sFormatted = "";
sFormatted = ( int.Parse( sOrig ) ).ToString( "00000" );

If you're a little suspect of the data being returned then put a try/catch
around the call to int.Parse (probably a good idea anyways).

Does that do it for you?

Tyson
 
Most probably, not.


Tyson Kamp said:
Well, I guess if the column type is text you could iterate through the
datasource after populating it and for each row do something like (C# syntax)

string sOrig = "12", sFormatted = "";
sFormatted = ( int.Parse( sOrig ) ).ToString( "00000" );

If you're a little suspect of the data being returned then put a try/catch
around the call to int.Parse (probably a good idea anyways).

Does that do it for you?

Tyson
 
Do you have access to the T-SQL that generates the result set? If so, try

select REPLACE( STR(your_column_name, 5), ' ', '0' ) from your_table_name

This assumes the source column is a number, but you get the idea. I'm not
sure if STR and REPLACE are supported in Access (I did this with SQL Server).
Also, this is getting a little convoluted, but given the details I have....

Tyson
 
Tyson, thanks for all your help.
I was trying to avoid formatting a field in SQL statement.
 
Back
Top