?
Solved

Datagrid binding - custom formatting

Posted on 2005-04-14
8
Medium Priority
?
286 Views
Last Modified: 2008-01-09
Experts,

I am binding a datagrid to a dataset.  I want to be able to customize a format so that the data appears how I want it.  For example, the raw data coming in from DB2 can be a 10 bytes long.  In that case, I want to format it like a phone number.  If it's longer than 10 bytes, I want to format it another way.  So, in other words, I want to create my own formatting routines instead of using the default ones in .NET that I assign to the format property of my DataGridTextBoxColumn.  See code below:

                  DataGridTableStyle tableStyle = new DataGridTableStyle();
                  tableStyle.MappingName = "VPN";

                  DataGridTextBoxColumn column = new DataGridTextBoxColumn();
                  column.MappingName = "CU_ID_NO";
                  column.HeaderText = "Customer ID";
                  column.Width = 40;
                  column.Format =  ?????

                  tableStyle.GridColumnStyles.Add(column);

Is there a way to create a formatting routine so I can format my db2 data a certain way, other than the standard datetime, currency, etc formatting expressions that are built in???

Thank you!
Scott
0
Comment
Question by:sgildner
  • 3
  • 2
  • 2
7 Comments
 
LVL 8

Expert Comment

by:rajaloysious
ID: 13781498
Yes it is all possible...
See if this is useful
http://www.codeproject.com/csharp/Apply_DataGridTableStyle.asp

cheers
0
 
LVL 1

Author Comment

by:sgildner
ID: 13781652
I've seen that article before.   This assigns a string format to the textColumn format property.  But see how they use "c" and "yyyy-MMM-dd"?  We want to create our own!

//this will help you to show data in currency form
textColumn.Format=System.String.Format("c",textColumn.TextBox);
//this will format and show the date in yyyy-MMM-dd format
textColumn.Format=System.String.Format("yyyy-MMM-dd",textColumn.TextBox);

//this will format and show the date in dd-MMM-yyyy format
textColumn.Format=System.String.Format("dd-MMM-yyyy",textColumn.TextBox);

//this will help you to show the time information excluding the date.
textColumn.Format=System.String.Format("hh:mm:ss",textColumn.TextBox);
0
 
LVL 11

Expert Comment

by:Agarici
ID: 13781980
to create your own format in the datagrid, make a class that derives from cultureinfo or simply implements iformatprovier
assign an instance of that cass to datagridcolumn.formatinfo, set datgridcolumn.format to your custom string
and there you go... everything is done.

hth,
A.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:sgildner
ID: 13782790
I think you're onto something!  I saw this at some point in my travels...can you provide a quick code sample or a link?!?   Thanks a bunch
0
 
LVL 8

Expert Comment

by:rajaloysious
ID: 13789762
0
 
LVL 1

Author Comment

by:sgildner
ID: 13790054
No, I don't need to create my own columnstyle.  The built in textbox style is fine, I just want to create my own format within that.  I am looking at Iformatprovider and formatinto as Agarici suggested, but having a slow go at it..  Thanks
0
 
LVL 11

Accepted Solution

by:
Agarici earned 750 total points
ID: 13804239
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month17 days, 7 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question