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.

databound grid view date/time

Thread ID:





12707 Apr 8,2004 08:01 AM Apr 12,2004 08:45 AM Windows Forms 7
Tags: GridControl
Administrator [Syncfusion]
Asked On April 8, 2004 08:01 AM

A databound grid is loaded with data, and column 1 is a date/time field in the database. By default, the datagrid displays this as a date field only and automatically brings in the datepicker. How can I eliminate the datepicker and instead just display the data''s date/time as a text? I changed the format to a textbox for that column, but it still displays it with the datepicker.

Administrator [Syncfusion]
Replied On April 8, 2004 09:16 AM

Hi Kelly, Please try changing the cell type to textbox and set the format to include the both date and time. //format column so no dropdown GridStyleInfo style = this.gridDataBoundGrid1.Binder.InternalColumns[0].StyleInfo; style.CellType = "TextBox"; style.CellValueType = typeof(DateTime); style.Format = "MM/dd/yy HH:mm:ss:fff"; Here is a sample Regards, Jay N

Administrator [Syncfusion]
Replied On April 8, 2004 10:16 AM

My project is in vb am I''m having trouble translating a line of code: style.CellValueType = typeof(DateTime); Dim style As New GridStyleInfo style = sfDatagrid.Binder.InternalColumn(0).StyleInfo style.CellType = "TextBox" Thanks!

Administrator [Syncfusion]
Replied On April 8, 2004 11:59 AM

Hi Kelly, Sorry for the inconvenience. Here is the VB code. ''format column so no dropdown Dim style As GridStyleInfo = Me.gridDataBoundGrid1.Binder.InternalColumns(0).StyleInfo style.CellType = "TextBox" style.CellValueType = GetType(DateTime) style.Format = "MM/dd/yy HH:mm:ss:fff" Here is the VB sample Regards, Jay N

Administrator [Syncfusion]
Replied On April 8, 2004 12:40 PM

Jay, Thanks for the VB sample. I''m getting an error on line: Dim style As GridStyleInfo = Me.sfDatagrid.Binder.InternalColumns(1).StyleInfo Error message: =================== An unhandled exception of type ''System.ArgumentOutOfRangeException'' occurred in mscorlib.dll Additional information: Index was out of range. Must be non-negative and less than the size of the collection. =================== I''ve tried to use a different col index number to see if maybe my index was off. Basically, the dataset is first col: text type second col: date/time (this is the col that I''d wanted to eliminate the datepicker) My datagrid is built by running a sql statement that returns an un-typed dataset but I''ve also removed a few columns from the dataset. ds.Tables(0).Columns.Remove("ColName") myDatatGrid.datasource = ds.tables(0)

Administrator [Syncfusion]
Replied On April 8, 2004 04:37 PM

Hi Kelly, Before this line, try checking your datatable''s column count like ds.tables(0).Columns.Count Dim style As GridStyleInfo = Me.sfDatagrid.Binder.InternalColumns(1).StyleInfo. I guess the indexer digit is greater than the columns present in the table. Or you can try giving the columnname instead of the integer to see if that helps. Dim style As GridStyleInfo = Me.sfDatagrid.Binder.InternalColumns("Colname").StyleInfo. Regards, Jay N

Administrator [Syncfusion]
Replied On April 12, 2004 08:06 AM

It turns out that the column index of the date column is -1. myDataGrid.NameToColIndex("myDateColName") Any thoughts on why the index would be a negative number? Thanks.

Administrator [Syncfusion]
Replied On April 12, 2004 08:45 AM

The -1 means that it cannot find the name, "myDateColName". This is case sensitive. Is there a column in your DataTable whose column name is exactly "myDateColName"? Have you explicitly added GridBoundColumns to the Me.sfDatagrid.GridBoundColumns collection? If so, instead of using Me.sfDatagrid.Binder.InternalColumns, use Me.sfDatagrid.GridBoundColumns. (This would explain why the column could not be found in sfDatagrid.Binder.InternalColumns).


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.