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.

Changing Date format in GDBG generates an edition error

Thread ID:

Created:

Updated:

Platform:

Replies:

22221 Dec 7,2004 07:52 AM Dec 8,2004 07:56 AM Windows Forms 4
loading
Tags: GridControl
Rodolphe Billottet
Asked On December 7, 2004 07:52 AM

Hi I have a GBDB bound to a DataTable containing dates. I want to change the date format (year displayed with 2 digits) whitout modifying the regional settings. I have tried to change the format of the grid model, but it haves no effect. grid.Model.ColStyles[colName].Format="dd/MM/yy" So, I have overriden PrepareViewStyleInfo to change the format and it works fine. protected override void OnPrepareViewStyleInfo(GridPrepareViewStyleInfoEventArgs e) { if(e.Style.CellValueType == typeof(System.DateTime)) { e.Style.Format = "dd/MM/yy"; } base.OnPrepareViewStyleInfo(e); } But now, I can''t edit the date anymore. It seems that, when I key in a date like 07/12/04, the date is rejected by the DataTable. And when I key in a date like 07/12/2004, the date is rejected by the Grid. How can I do ?

Administrator [Syncfusion]
Replied On December 7, 2004 08:03 AM

In a GridDataBoundGrid, instead of using ColStyles, you need to use the GridBoundColumn.StyleInfo for the column instead. If you have explicitly added GridBoundColumns, then you get this styleinfo using grid.GridBoundColumns["MyColumnName"].StyleInfo. If you have not explicitly added GridBoundColumns, then you use grid.Binder.InternalColumns["MyColumnName"].StyleInfo to get at the style object. Once you have the style object, in addition to setting style.Format, you also will need to set the style.CellValueType to be DateTime if you want the formatting to ''take''. If you cannot set the CellvalueType for some reason (like your datasource does not contain a DateTime object), then you can handle the DrawCellDisplayText event, and there set e.Text to be the formatted string you want to see.

Administrator [Syncfusion]
Replied On December 7, 2004 09:50 AM

Thank you for answering. In my case, the DataTable change often, and the structure of the DataTable is always the same. So, as you advise, I have used the GridBoundColumns. Now, I dont have the date problem anymore, but I got another small problem. When the grid is bind to an empty DataTable (Table with columns but without row), the columns are displayed without the header text.

Administrator [Syncfusion]
Replied On December 7, 2004 10:49 AM

What version are you using? In 2.1.0.9, if I drop a GridDataboundGrid on a form, and then out this code in Form.load, I do not see a missing header. If you can post a sample showing the problem, maybe we can spot it.
private void Form1_Load(object sender, System.EventArgs e)
{
	DataTable dt = new DataTable("MyTable");
	int nCols = 4;
	for(int i = 0; i < nCols; i++)
		dt.Columns.Add(new DataColumn(string.Format("Col{0}", i)));

	this.gridDataBoundGrid1.GridBoundColumns.Add(new GridBoundColumn());
	this.gridDataBoundGrid1.GridBoundColumns[0].MappingName = "Col1";
	this.gridDataBoundGrid1.GridBoundColumns[0].HeaderText ="Some text";
	this.gridDataBoundGrid1.DataSource = dt;	 
}

Rodolphe Billottet
Replied On December 8, 2004 07:56 AM

Hello, I''m sorry, there was an error in my program. When I create an instance of GridBoundColumn, a lot of attributs of the instance are not defined. new GridBoundColumn(this.Binder.InternalColumns[colIndex].PropertyDescriptor); So, I prefer to modify the existing StyleInfo Binder.InternalColumns[].StyleInfo Now, all is OK! Thanks.

CONFIRMATION

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.

;