By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,478 Members | 1,374 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,478 IT Pros & Developers. It's quick & easy.

[DataGrid] Formatting values before binding

P: n/a
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.
Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
string.Format("{0:000000}", number);
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Jesper Stocholm" <j@stocholm.invalid> wrote in message
news:Xn************************@207.46.248.16...
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.

Nov 16 '05 #2

P: n/a
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]
- mv*@spam.guard.caspershouse.com

"Jesper Stocholm" <j@stocholm.invalid> wrote in message
news:Xn************************@207.46.248.16...
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.

Nov 16 '05 #3

P: n/a
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.

:o)

--
Jesper Stocholm http://stocholm.dk

Programmer's code comment:
//It probably makes more sense when you're stoned.
Nov 16 '05 #4

P: n/a
Jesper Stocholm wrote:
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, :o)

--
Jesper Stocholm http://stocholm.dk

Programmer's code comment:
//It probably makes more sense when you're stoned.
Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.