473,395 Members | 1,675 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

[DataGrid] Formatting values before binding

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
4 1556
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order...
2
by: Hrvoje Vrbanc | last post by:
Hello all! I have quite an strange question: I'm using DataGrid to display the results of a query stored in a DataSet. I use data binding with DataBinder.Eval statement (like e.g. <%#...
4
by: vinay | last post by:
Hi, I am binding a dataset to DataGrid. I have a field which returns decimal values. Ex: 0.23 In dataGrid it is showing only 0 insted of 0.23!
7
by: Matthew Wieder | last post by:
Hi - I have a datagrid that has a black header and the rows alternate white and gray. The problem is that until items are added to the grid, the grid appears as a large black rectangle, which is...
3
by: McNutt Consulting | last post by:
I'm trying to implement a datagrid with dynamically created columns. The data is coming out of a very simple XML file, and it's bound through a dataview. The datagrid is just a shell definition...
4
by: hope | last post by:
Hi, How can I format a string field using Data Formatting Expression property in datagrid? For example: format last name from BROWN to Brown. Thanks
4
by: Ed Bick | last post by:
I know how to do this stuff so easily in VB6......... 3 questions. I have loaded a grid by binding it to a dataset. All is well with that. 1) How do I retrieve the value of a column when a...
2
by: Randall Parker | last post by:
Suppose you want to do either of these: A) Set display properties (e.g. color or boldness of text) of a cell based on a value of another cell in the same row. B) Set the display properties of...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.