473,385 Members | 1,593 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,385 software developers and data experts.

Formatting fields in a datatable

Hi,

I have written a custom multi column listbox control that I pass a
datatable to.

the issue is that if there are date fields then these may
be in the wrong format or any other field formatting

So when I create the control I pass a object that defines
the label, width and format of each column.

How do I use the format field (which is a string) to generically
format a any field the in the datatable.

mystring = dr[i].ToString(myheader.Format];

Something like that is what I want to do.

But ToString doesn't support format

any ideas
rotsey.
Aug 28 '07 #1
4 2193
Well, you could check if dr[i] supports IFormattable; this has a
ToString(string format, IFormatProvider formatProvider)

Marc
Aug 28 '07 #2
Sorry dr is a DatatRow object

I don't think it does.

Any other ideas?

"Marc Gravell" <ma**********@gmail.comwrote in message
news:OT**************@TK2MSFTNGP04.phx.gbl...
Well, you could check if dr[i] supports IFormattable; this has a
ToString(string format, IFormatProvider formatProvider)

Marc

Aug 28 '07 #3
Sorry dr is a DatatRow object
precisely: hence, dr[i] is the value of the i'th column, i.e. the
value you want to format... so if your column is a date, then this is
a boxed DateTime - which *does* implement IFormattable:

object val = dr[i];
IFormattable fVal = val as IFormattable;
string sVal = fVal == null ? Convert.ToString(val)
: fVal.ToString(format, CultureInfo.CurrentCulture);

Marc
Aug 28 '07 #4
ok thanks

"Marc Gravell" <ma**********@gmail.comwrote in message
news:Oj*************@TK2MSFTNGP06.phx.gbl...
>Sorry dr is a DatatRow object
precisely: hence, dr[i] is the value of the i'th column, i.e. the value
you want to format... so if your column is a date, then this is a boxed
DateTime - which *does* implement IFormattable:

object val = dr[i];
IFormattable fVal = val as IFormattable;
string sVal = fVal == null ? Convert.ToString(val)
: fVal.ToString(format, CultureInfo.CurrentCulture);

Marc

Aug 28 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ImraneA | last post by:
Hi there Have a database, where front-end interface allows user to select a ms access database. From there, standard tables are linked. Routine, that creates a spreadsheet, for each table a...
2
by: Sara | last post by:
The problem: Conditional formatting bold, red when field Value < date() sets the field background to white - always - whether condition is met or not. I want the field unfilled and just red/bold...
4
by: deko | last post by:
I've heard it's best not to have any formatting specified for Table fields (except perhaps Currency), and instead set the formatting in the Form or Report. But what about Yes/No fields? When I...
5
by: Jeff Cook | last post by:
Hi I have a DataGrid that I am using to display a .xml file (that has a schema in a .xsd), like this:- ds.ReadXmlSchema(sDataPath + "Data.xsd"); ds.ReadXml(sDataPath + "Data.xml",...
3
by: jayuya | last post by:
Can anyone give a sample code, tip, or a web link with an example of how to format data to currency. eg: $3451.25 I set a dataadapter and I fill the dataset from a SQL Statement, but some...
0
by: Ryan Smith | last post by:
I have the following Code and I am looking to set the first column to 200 pixels. How do I do this? Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles...
2
by: Lars Erik Nes | last post by:
Hi all. I have a problem. I get all my data from a dataset (not mssql) and in that dataset i have a table called "Activity". In this table i have a few date fields. When i display the dataset...
4
by: Ken Wigle | last post by:
All, I would be very grateful for any help on this question. I have an application in asp.net 2.0 where I dynamically create a datatable and then bind that to a gridview. Unfortunately, the...
8
by: Typehigh | last post by:
I have many text fields with conditional formatting applied, specifically when the condition is "Field Has Focus". Without any events associated with the fields the conditional formatting works...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.