[DataGrid] Formatting values before binding

J

Jesper Stocholm

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?
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
J

Jesper Stocholm

Nicholas said:
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.

:blush:)
 
J

Jesper Stocholm

Jesper said:
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, :blush:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top