New to Telerik UI for WinForms? Start a free 30-day trial
Creating Custom Editor
Updated over 6 months ago
RadGanttView allows you to replace the standard editors with a custom ones. The following examples demonstrates how to replace the spin editor with a track bar editor. All editors inherit from BaseInputEditor. So, you have to inherit from this class and override several methods:
C#
public class GanttViewTrackBarEditor : BaseInputEditor
{
public override object Value
{
get
{
RadTrackBarElement editor = (RadTrackBarElement)this.EditorElement;
return editor.Value;
}
set
{
RadTrackBarElement editor = (RadTrackBarElement)this.EditorElement;
if (value != null && value != DBNull.Value)
{
editor.Value = Convert.ToInt32(value);
}
else
{
editor.Value = 0;
}
}
}
public override void BeginEdit()
{
base.BeginEdit();
this.EditorElement.Focus();
((RadTrackBarElement)this.EditorElement).ValueChanged += new EventHandler(TrackBarEditor_ValueChanged);
}
void TrackBarEditor_ValueChanged(object sender, EventArgs e)
{
this.OnValueChanged();
}
public override bool EndEdit()
{
((RadTrackBarElement)this.EditorElement).ValueChanged -= TrackBarEditor_ValueChanged;
return base.EndEdit();
}
protected override RadElement CreateEditorElement()
{
RadTrackBarElement element = new RadTrackBarElement();
element.Minimum = 0;
element.Maximum = 100;
element.TickStyle = Telerik.WinControls.Enumerations.TickStyles.Both;
element.SmallTickFrequency = 10;
element.LargeTickFrequency = 0;
element.BodyElement.ScaleContainerElement.TrackBarLineElement.Margin = new Padding(0, 3, 0, 3);
return element;
}
public override Type DataType
{
get { return typeof(int); }
}
}
In the EditorRequired event you can replace the default editor:
C#
private void GanttViewElement_EditorRequired(object sender, GanttViewEditorRequiredEventArgs e)
{
if (e.EditorType == typeof(GanttViewSpinEditor))
{
e.EditorType = typeof(GanttViewTrackBarEditor);
}
}
