• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 290
  • Last Modified:

Datagrid binding - custom formatting

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
sgildner
Asked:
sgildner
  • 3
  • 2
  • 2
1 Solution
 
rajaloysiousCommented:
Yes it is all possible...
See if this is useful
http://www.codeproject.com/csharp/Apply_DataGridTableStyle.asp

cheers
0
 
sgildnerAuthor Commented:
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
 
AgariciCommented:
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
sgildnerAuthor Commented:
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
 
rajaloysiousCommented:
0
 
sgildnerAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now