Hello,
I´´m trying to insert a column in Radgridview in winforms using the following code:
Dim dateTimeColumn As New GridViewDateTimeColumn()
dateTimeColumn.UniqueName =
"DateTimeColumn"
dateTimeColumn.HeaderText =
"Test"
dateTimeColumn.FieldName =
"TestDate"
dateTimeColumn.FormatString =
"{0:MM/dd/yy}"
RadGridProjects.MasterGridViewTemplate.Columns.Add(dateTimeColumn)
I also tried do insert this column in design mode, but, the column always appear with the format 01/01/2000 02 00:00:00 instead of 01/01/2000.
What am I doing wrong?
Thank You
LM
5 Answers, 1 is accepted
Thank you for writing.
Currently, there is an issue with FormatString for unbound columns. It will be addressed in one of our future releases.
For the time being, you can implement the functionality in your own code. Assign raw date values to the RadGridView at the state of binding. I used the following binding scheme:
GridViewDataColumn dataCol1 = new GridViewDataColumn(); |
GridViewDataColumn dataCol2 = new GridViewDataColumn(); |
GridViewDateTimeColumn timeCol3 = new GridViewDateTimeColumn(); |
this.radGridView1.Columns.Add(dataCol1); |
this.radGridView1.Columns.Add(dataCol2); |
this.radGridView1.Columns.Add(timeCol3); |
DateTime dt = DateTime.Now; |
for (int i = 0; i < 100; ++i) |
{ |
dt = dt.AddDays(1); |
this.radGridView1.Rows.Add( |
new object[] { "a", i.ToString(), dt }); |
} |
In order to apply the formatting to the date, you only need handle the CellFormatting event as shown below:
radGridView1.CellFormatting += new CellFormattingEventHandler(radGridView1_CellFormatting); |
void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) |
{ |
//execute the code only for the datetime column |
//in this case it bears an index of 2 |
if (e.CellElement.ColumnIndex == 2) |
{ |
//only apply formatting to unformatted values |
if (!e.CellElement.Text.StartsWith("0:")) |
{ |
DateTime temp = DateTime.Parse(e.CellElement.Text); |
e.CellElement.Text = temp.ToString("{0:MM/dd/yy}"); |
} |
} |
} |
I hope this helps. If you have additional questions, feel free to contact me.
Best wishes,
Nikolay
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Convert(VARCHAR(10), TABQOT_Proposals.EntryDate , 111)
This solved my problem.
Thank You.
LM
I am glad to hear that the issue is resolved.
If you have additional questions, do not hesitate to contact me.
Kind regards,
Nikolay
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
I would like to note that this is quite an old post since 2008 and RadGridView has been majorly refactored during the years. If you have any specific setup in your grid, it would be greatly appreciated if you can share it with us. Thus, we would get better understanding of the precise case.
RadGridView offers a GridViewDateTimeColumn which provides date entry and formatting for DateTime data types. This column has a FormatString property that specifies cell's format and Format property that specifies the editor's format. The following forum post demonstrates how to achieve different formatting for the cells in editor mode and not in edit mode: https://www.telerik.com/forums/gridviewdatetimecolumn-need-date-without-time#z0wEIqLyJU6vqtuKRr-f5g
The following help article gives more information about how to setup the GridViewDateTimeColumn: https://docs.telerik.com/devtools/winforms/controls/gridview/columns/column-types/gridviewdatetimecolumn
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.