Data Formatting in Datagrid

  • Thread starter Thread starter Pinkesh Jain
  • Start date Start date
P

Pinkesh Jain

Hi,

Is there anyway we can format the data that appears in the
Datagrid?

In non Compact framework we have the .Format property of
the DatagridTextBoxColumn which serves the purpose. But in
the Compact Framework this property isn't there.
Wht are the other options?

Thanks.
 
Generally the solution is to create a new Expression column on your
DataTable which exposes your data in the required format, and then show this
rather than the underlying column. What type of formatting do you want to
apply?

Peter
 
Hi Peter,

Actually I'm binding the Datagrid with a list of objects.
And I'm setting the Column and table mappings for the
same, by adding a new TableStyle object to the Datagrid's
TableStyles collection.

Now, the Property in the object can either be an Integer,
Decimal, or a Date. In that case I need to display the
data in some predetermined format (maybe different from
the locale formats).

I'm able to achive the same on Windows based application,
by assigning the .Format property of the
DatagridTextBoxColumn to the required format. But I'm
unable to do the same with the Compact Framework.
Wht are your thoughts?
 
Unfortunately this is a limitation of the CF Grid, it doesn't have the
capability to perform any additional formatting of the bound values. You'll
need to either use an intermediate collection of some kind which gives you
the flexibility to convert the values into something suitable for display,
or add additional string properties to the object to export the values in
the required format. e.g.
public string StartDateString
{
get
{
return this.StartDate.ToShortDateString();
}
}

Peter
 
Back
Top