|
-
Jun 18th, 2007, 03:12 AM
#1
Thread Starter
Lively Member
[RESOLVED] format datagrid column to display only the time
Hi,
I'm using compact framework with VS 2005.
How can I format a datagrid column to display only the time.
Thanks
-
Jun 18th, 2007, 07:17 AM
#2
Frenzied Member
Re: format datagrid column to display only the time
HI,
For a time using your own date
FormatDateTime(mydate, DateFormat.ShortTime)
else
FormatDateTime(Date.Now, DateFormat.ShortTime)
for the current date.
Is that what you mean?
Pete
-
Jun 18th, 2007, 08:21 AM
#3
Re: format datagrid column to display only the time
Did you follow the link I provided in your other thread? Question 44 on that page is "How do I format a date column in a datagrid?". It shows you how to set the format for a DataGridTextBoxColumn. Go to the MSDN library topic for the DataGridTextBoxColumn class and it has a code example for adding one to a grid. Look up "date formatting" or "time formatting" on MSDN and you'll find the format strings you can assign to the Format property of your DataGridTextBoxColumn.
Many questions aren't going to be solved by finding a ready-made solution in one place. You have to construct a solution by breaking the problem into pieces and solving each piece on its own.
-
Jun 18th, 2007, 10:42 PM
#4
Thread Starter
Lively Member
Re: format datagrid column to display only the time
Yes I was able to solve the problem with some support from that link...
Just for anyne who mght come across the same problem...you use tablestyles to format datagrid columns in compact framework apps.
this example I came across might be useful.
Code:
private void Form1_Load(object sender, System.EventArgs e)
{
string dataTableName = "theTable";
//add a tablestyle to the grid so there will be custom columnstyles available
// after the datasource has been set....
DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = dataTableName;
this.dataGrid1.TableStyles.Add(ts);
this.dataGrid1.DataSource = GetTheTable(dataTableName);
//now default customcolumnstyles have been created, so we can use them to set properties
DataGridTextBoxColumn dgtbc;
//format the int
dgtbc = dataGrid1.TableStyles[0].GridColumnStyles[0] as DataGridTextBoxColumn;
if(dgtbc != null)
dgtbc.Format = "n0";
//format the double
dgtbc = dataGrid1.TableStyles[0].GridColumnStyles[1] as DataGridTextBoxColumn;
if(dgtbc != null)
dgtbc.Format = "f3"; // 0r "#.000";
//format the double as currency
dgtbc = dataGrid1.TableStyles[0].GridColumnStyles[2] as DataGridTextBoxColumn;
if(dgtbc != null)
dgtbc.Format = "c4";
//format the date
dgtbc = dataGrid1.TableStyles[0].GridColumnStyles[3] as DataGridTextBoxColumn;
if(dgtbc != null)
{
dgtbc.Format = "t"; // t is for time. d is for date dgtbc.Width = 100; //size it
}
}
Last edited by sunshine123; Jun 18th, 2007 at 10:45 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|