We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

DateTime string to ShortDate in DataBoundGrid

Thread ID:





17368 Aug 6,2004 11:33 AM Aug 7,2004 04:20 AM Windows Forms 2
Tags: GridControl
kevin musters
Asked On August 6, 2004 11:33 AM

I have a datatable gets it''s datetimes as strings. I set my datasource of my databoundgrid to a datatable. When I load the grid, the date appears as "09/12/1998 12:00:00 AM" I want to format that column as the localized ShortDate of the computer (in this case is "09/12/1998") How can I achieve this without making the date column a drop down datepicker? Thanks, I''m really stuck.

Administrator [Syncfusion]
Replied On August 6, 2004 11:37 AM

You should set the GridBoundColumnStyleInfo.CellValueType to typeof(DateTime) and then set the GridBoundColumnStyleInfo.Format to display what you want to see. If you do not want to see the buttons, then set GridBoundColumnStyleInfo.ShowButtons = hide.

Administrator [Syncfusion]
Replied On August 7, 2004 04:20 AM

Here is a FormLoad that populates a GridDataBoundGrid with DateTime strings, and then formats one of the columns with the locale short date format.
private void Form1_Load(object sender, System.EventArgs e)
	DataTable dt = new DataTable("MyTable");
	int nCols = 4;
	int nRows = 10;
	for(int i = 0; i < nCols; i++)
	dt.Columns.Add(new DataColumn(string.Format("Col{0}", i)));
	for(int i = 0; i < nRows; ++i)
		DataRow dr = dt.NewRow();
		for(int j = 0; j < nCols; j++)
			dr[j] = string.Format("{0}", DateTime.Now);
	this.gridDataBoundGrid1.DataSource = dt;
	GridStyleInfo style = this.gridDataBoundGrid1.Binder.InternalColumns[2].StyleInfo;
	style.CellValueType = typeof(DateTime);
	style.Format = "d"; //local short date format


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.