HighTechTalks DotNet Forums  

[DataGrid] Formatting values before binding

Dotnet Framework (WinForms DataBinding) microsoft.public.dotnet.framework.windowsforms.databinding


Discuss [DataGrid] Formatting values before binding in the Dotnet Framework (WinForms DataBinding) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Jesper Stocholm
 
Posts: n/a

Default [DataGrid] Formatting values before binding - 09-20-2004 , 09:07 AM






I have a WinForm datagrid that receives data from a DataSet. One of the
colums is anm INT-column from the database, and I would like to format
these INTs before binding them to the control.

I format the grid by applying a style to it, and I have seen in the doc
that there on the object DataGridTextBoxColumn is a property called
..Format, that I have a feeling might be usefull to me.

I need to prefix the ints with zeros so that the result is like

210343 -> 210343
123 -> 000123

How you I create a format string that will do this for me?

Can you guys give me a hint on this?

--
Jesper Stocholm http://stocholm.dk

Programmer's code comment:
//It probably makes more sense when you're stoned.

Reply With Quote
  #2  
Old   
Dennis Myrén
 
Posts: n/a

Default Re: [DataGrid] Formatting values before binding - 09-20-2004 , 09:13 AM






string.Format("{0:000000}", number);


--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Jesper Stocholm" <j (AT) stocholm (DOT) invalid> wrote

Quote:
I have a WinForm datagrid that receives data from a DataSet. One of the
colums is anm INT-column from the database, and I would like to format
these INTs before binding them to the control.

I format the grid by applying a style to it, and I have seen in the doc
that there on the object DataGridTextBoxColumn is a property called
.Format, that I have a feeling might be usefull to me.

I need to prefix the ints with zeros so that the result is like

210343 -> 210343
123 -> 000123

How you I create a format string that will do this for me?

Can you guys give me a hint on this?

--
Jesper Stocholm http://stocholm.dk

Programmer's code comment:
//It probably makes more sense when you're stoned.



Reply With Quote
  #3  
Old   
Nicholas Paldino [.NET/C# MVP]
 
Posts: n/a

Default Re: [DataGrid] Formatting values before binding - 09-20-2004 , 09:16 AM



Jesper,

You can use a format of "000000" I believe. It should be interpreted as
a custom format, and make sure that six digits are used to represent the
value.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp (AT) spam (DOT) guard.caspershouse.com

"Jesper Stocholm" <j (AT) stocholm (DOT) invalid> wrote

Quote:
I have a WinForm datagrid that receives data from a DataSet. One of the
colums is anm INT-column from the database, and I would like to format
these INTs before binding them to the control.

I format the grid by applying a style to it, and I have seen in the doc
that there on the object DataGridTextBoxColumn is a property called
.Format, that I have a feeling might be usefull to me.

I need to prefix the ints with zeros so that the result is like

210343 -> 210343
123 -> 000123

How you I create a format string that will do this for me?

Can you guys give me a hint on this?

--
Jesper Stocholm http://stocholm.dk

Programmer's code comment:
//It probably makes more sense when you're stoned.



Reply With Quote
  #4  
Old   
Jesper Stocholm
 
Posts: n/a

Default Re: [DataGrid] Formatting values before binding - 09-20-2004 , 09:39 AM



Nicholas Paldino [.NET/C# MVP] wrote:

Quote:
Jesper,

You can use a format of "000000" I believe. It should be
interpreted as
a custom format, and make sure that six digits are used to represent
the value.

Hope this helps.
It did, thank you very much.

)

--
Jesper Stocholm http://stocholm.dk

Programmer's code comment:
//It probably makes more sense when you're stoned.


Reply With Quote
  #5  
Old   
Jesper Stocholm
 
Posts: n/a

Default Re: [DataGrid] Formatting values before binding - 09-21-2004 , 01:52 AM



Jesper Stocholm wrote:

Quote:
Nicholas Paldino [.NET/C# MVP] wrote:

Jesper,

You can use a format of "000000" I believe. It should be
interpreted as
a custom format, and make sure that six digits are used to represent
the value.

Hope this helps.

It did, thank you very much.
An additional question:

Is it possible to use the .Format-property to apply conditional formatting?

Say I have a DateTime column in a DataSet that I need to bind to a
DataGrid. If the contents of some of the rows is 31-12-1800 00:00:00 (or
any other date) I need to display simply an empty string and not the date
itself.

Can this be done as well?

Thanks, )

--
Jesper Stocholm http://stocholm.dk

Programmer's code comment:
//It probably makes more sense when you're stoned.


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.