Hi
Are you running a ASP.NET or winforms application?
Are you using a Datagrid?
Based on my research, here is some code about how to do that in a Grid view
in winform.
1. Set current thread's date pattern to "yyyy-MM-dd"
[STAThread]
static void Main()
{
CultureInfo ci =
(CultureInfo)CultureInfo.CurrentCulture.Clone();
ci.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd";
Thread.CurrentThread.CurrentCulture = ci;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
2. For the string as "Date: xxxx-xx-xx"
private void Form1_Load(object sender, EventArgs e)
{
DataTable table = new DataTable();
//// Create the first column.
DataColumn dateColumn = new DataColumn();
dateColumn.DataType = System.Type.GetType("System.DateTime");
dateColumn.ColumnName = "date";
dateColumn.DefaultValue = "2002-4-18";
//// Create the second, calculated, column.
DataColumn testColumn = new DataColumn();
testColumn.DataType = System.Type.GetType("System.String");
testColumn.ColumnName = "Test";
testColumn.Expression = "'Date: ' + SubString(Convert(date,
'System.String'),1,10)";
// Add columns to DataTable.
table.Columns.Add(dateColumn);
table.Columns.Add(testColumn);
DataRow row = table.NewRow();
table.Rows.Add(row);
DataView view = new DataView(table);
this.dataGridView1.DataSource = view;
}
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.