473,651 Members | 2,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[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 DataGridTextBox Column 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 1570
string.Format(" {0:000000}", number);
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Jesper Stocholm" <j@stocholm.inv alid> 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 DataGridTextBox Column 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.co m

"Jesper Stocholm" <j@stocholm.inv alid> 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 DataGridTextBox Column 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
2584
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 date, name, address etc) about the selected row in the datagrid... My problem is when I enter a new record in the details tabpage (saves data to database), and go back to the datagrid. Only the data from the PM-table
2
2328
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. <%# DataBinder.Eval(Container.DataItem, "ColumnName") %>). Now the tricky part: is it possible to render one more table row for each record that would be span over several columns and contain some further databound informations? What I want to say is that I...
4
7431
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
4670
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 quite ugly. The black area is larger then it is once an item is added. How can I solve this problem either by: A) Having only the header black and the rest of the empty block white or gray (preffered solution) B) Having the color gray or white...
3
4067
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 with no column definitions in the ..aspx file. The grid is binding fine with all the data being displayed, but my numeric columns aren't being formatted. I'm using the "dataformattextstring", but it doesn't seem to be working. Is there...
4
3229
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
1092
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 user clicks on a row? I use a Sheriden grid in VB6 and would do something like: MyString = MyGrid.Columns(n).Text
2
1090
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 a whole row based on values of one or more cells in that row. Well, these seem like reasonable things to want to do. If one was writing one's own code to spit out HTML table tr and td tags like in days of old (like, say, 6 years
9
2713
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 code: <script runat="server"> Dim sqlConn As New SqlConnection(".....") Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not (Page.IsPostBack) Then FillDataGrid()
0
8275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8802
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8697
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7297
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1587
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.