1 Answer, 1 is accepted
0
Accepted

Richard Slade
Top achievements
Rank 2
answered on 27 Jan 2011, 10:00 PM
Hello Beck,
The following example uses the CellEditorInitialized event to format the editor to a time, and then replace the calendar drop down button with the up/down arrows that are needed on a time based editor.
Designer File
Form1.cs
Hope that helps, but let me know if you have any questions
Richard
The following example uses the CellEditorInitialized event to format the editor to a time, and then replace the calendar drop down button with the up/down arrows that are needed on a time based editor.
Designer File
namespace
RadGridView_Basic_C
{
partial
class
Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private
System.ComponentModel.IContainer components;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected
override
void
Dispose(
bool
disposing)
{
if
(disposing && (components !=
null
))
{
components.Dispose();
}
base
.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private
void
InitializeComponent()
{
this
.radGridView1 =
new
Telerik.WinControls.UI.RadGridView();
((System.ComponentModel.ISupportInitialize)(
this
.radGridView1)).BeginInit();
this
.SuspendLayout();
//
// radGridView1
//
this
.radGridView1.Location =
new
System.Drawing.Point(0, 0);
this
.radGridView1.Name =
"radGridView1"
;
this
.radGridView1.Size =
new
System.Drawing.Size(457, 510);
this
.radGridView1.TabIndex = 0;
this
.radGridView1.Text =
"radGridView1"
;
//
// Form1
//
this
.AutoScaleDimensions =
new
System.Drawing.SizeF(6F, 13F);
this
.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this
.ClientSize =
new
System.Drawing.Size(457, 556);
this
.Controls.Add(
this
.radGridView1);
this
.Name =
"Form1"
;
this
.Text =
"Form1"
;
this
.Load +=
new
System.EventHandler(
this
.Form1_Load);
((System.ComponentModel.ISupportInitialize)(
this
.radGridView1)).EndInit();
this
.ResumeLayout(
false
);
}
#endregion
private
Telerik.WinControls.UI.RadGridView radGridView1;
}
}
Form1.cs
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
Telerik.WinControls.UI;
using
Telerik.WinControls;
using
Telerik.WinControls.Data;
using
Telerik.WinControls.UI.Export;
using
Telerik.WinControls.UI.Export.HTML;
using
Telerik.WinControls.RadControlSpy;
using
System.Globalization;
namespace
RadGridView_Basic_C
{
public
partial
class
Form1 : Form
{
private
List<Person> m_myList =
new
List<Person>();
public
Form1()
{
InitializeComponent();
}
private
void
Form1_Load(
object
sender, EventArgs e)
{
this
.radGridView1.AutoGenerateColumns =
false
;
this
.radGridView1.AllowAddNewRow =
false
;
this
.radGridView1.AllowEditRow =
true
;
m_myList.Add(
new
Person(10,
"Richard"
,
new
DateTime(2011,1,1,23,45,00)));
m_myList.Add(
new
Person(20,
"Stew"
,
new
DateTime(2011, 1, 1,12,34,55)));
m_myList.Add(
new
Person(30,
"Chris"
,
new
DateTime(2011, 1, 1,13,12,34)));
m_myList.Add(
new
Person(40,
"Peter"
,
new
DateTime(2011, 1, 1,16,25,10)));
radGridView1.DataSource = m_myList;
GridViewDecimalColumn idColumn =
new
GridViewDecimalColumn();
idColumn.Name =
"Id"
;
idColumn.HeaderText =
"Id"
;
idColumn.FieldName =
"Id"
;
this
.radGridView1.Columns.Add(idColumn);
GridViewTextBoxColumn nameColumn =
new
GridViewTextBoxColumn();
nameColumn.Name =
"Name"
;
nameColumn.HeaderText =
"Name"
;
nameColumn.FieldName =
"Name"
;
this
.radGridView1.Columns.Add(nameColumn);
GridViewDateTimeColumn timeColumn =
new
GridViewDateTimeColumn();
timeColumn.Name =
"Time"
;
timeColumn.FormatString =
"{0:T}"
;
timeColumn.HeaderText =
"Time"
;
timeColumn.FieldName =
"Time"
;
this
.radGridView1.Columns.Add(timeColumn);
this
.radGridView1.CellEditorInitialized +=
new
Telerik.WinControls.UI.GridViewCellEventHandler(
this
.radGridView1_CellEditorInitialized);
this
.radGridView1.BeginEditMode = RadGridViewBeginEditMode.BeginEditOnKeystrokeOrF2;
this
.radGridView1.MultiSelect =
true
;
this
.radGridView1.SelectionMode = GridViewSelectionMode.CellSelect;
}
void
radGridView1_CellEditorInitialized(
object
sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
if
(e.Column.Name ==
"Time"
)
{
var editManager = sender
as
GridViewEditManager;
var editor = editManager.ActiveEditor
as
RadDateTimeEditor;
if
(editor ==
null
)
return
;
RadDateTimeEditorElement editorElement = (RadDateTimeEditorElement)((RadDateTimeEditor)editor).EditorElement;
editorElement.ShowUpDown =
true
;
editorElement.Format = DateTimePickerFormat.Time;
}
}
class
Person
{
public
Person()
{ }
public
Person(
decimal
id,
string
name, DateTime time)
{
this
.Id = id;
this
.Name = name;
this
.Time = time;
}
public
decimal
Id {
get
;
set
; }
public
string
Name {
get
;
set
; }
public
DateTime Time {
get
;
set
; }
}
}
}
Hope that helps, but let me know if you have any questions
Richard