Unplanned
Last Updated: 15 Sep 2021 11:33 by ADMIN
Yoann
Created on: 15 Sep 2021 11:13
Category: GanttView
Type: Bug Report
0
RadGanttView: ItemValidating event is being fired three times if it is cancelled

Please use the following code snippet. Activate the editor for a cell and click another cell:

private DataSet weddingPlan;
public DataSet WeddingPlan {
    get 
    { 
        if(weddingPlan == null)
        {
            weddingPlan = new DataSet();
            using (StreamReader rdr = new StreamReader("TelerikWeddingPlanner.xml"))
            {
                weddingPlan.ReadXml(rdr);
            }
        }

        return weddingPlan;
    }
}

public Form1()
{
    InitializeComponent();

    // Events
    this.radGanttView1.GanttViewElement.EditorRequired += GanttViewElement_EditorRequired;
    this.radGanttView1.GanttViewElement.EditorInitialized += GanttViewElement_EditorInitialized;
    this.radGanttView1.GanttViewElement.ItemValidating += GanttViewElement_ItemValidating;
    this.radGanttView1.GanttViewElement.ItemValidated += GanttViewElement_ItemValidated;
    this.radGanttView1.GanttViewElement.ItemEdited += GanttViewElement_ItemEdited;
}

private void GanttViewElement_DoubleClick(object sender, EventArgs e)
{
    Debug.WriteLine("GanttViewElement_DoubleClick");
}

private void GanttViewElement_EditorRequired(object sender, GanttViewEditorRequiredEventArgs e)
{
    Debug.WriteLine("GanttViewElement_EditorRequired");
    
}

private void GanttViewElement_EditorInitialized(object sender, GanttViewItemEditorInitializedEventArgs e)
{
    Debug.WriteLine("GanttViewElement_EditorInitialized");
    
}

private void GanttViewElement_ItemValidated(object sender, GanttViewItemValidatedEventArgs e)
{
    Debug.WriteLine("GanttViewElement_ItemValidated");
    
}

private void GanttViewElement_ItemValidating(object sender, GanttViewItemValidatingEventArgs e)
{
    Debug.WriteLine("GanttViewElement_ItemValidating");
    Debug.WriteLine(e.Column.FieldName);
    e.Cancel = true;
}

private void GanttViewElement_ItemEdited(object sender, GanttViewItemEditedEventArgs e)
{
    Debug.WriteLine("GanttViewElement_ItemEdited");
    
}

private void Form1_Load(object sender, EventArgs e)
{
    this.radGanttView1.DataSource = WeddingPlan;


    this.radGanttView1.GanttViewElement.TaskDataMember = "Tasks";
    this.radGanttView1.GanttViewElement.ChildMember = "Id";
    this.radGanttView1.GanttViewElement.ParentMember = "ParentId";
    this.radGanttView1.GanttViewElement.TitleMember = "Title";
    this.radGanttView1.GanttViewElement.StartMember = "Start";
    this.radGanttView1.GanttViewElement.EndMember = "Finish";
    this.radGanttView1.GanttViewElement.ProgressMember = "Progress";
    this.radGanttView1.GanttViewElement.LinkDataMember = "Links";
    this.radGanttView1.GanttViewElement.LinkStartMember = "StartId";
    this.radGanttView1.GanttViewElement.LinkEndMember = "EndId";
    this.radGanttView1.GanttViewElement.LinkTypeMember = "LinkType";

    this.radGanttView1.GanttViewElement.Columns.Add(new GanttViewTextViewColumn("Id"));
    this.radGanttView1.GanttViewElement.Columns.Add(new GanttViewTextViewColumn("ParentId"));
    this.radGanttView1.GanttViewElement.Columns.Add(new GanttViewTextViewColumn("Title"));
    this.radGanttView1.GanttViewElement.Columns.Add(new GanttViewTextViewColumn("Start"));
    this.radGanttView1.GanttViewElement.Columns.Add(new GanttViewTextViewColumn("Finish"));

    this.radGanttView1.GanttViewElement.Columns[0].Visible = false;
    this.radGanttView1.GanttViewElement.Columns[1].Visible = false;
    this.radGanttView1.GanttViewElement.Columns[2].Width = 350;
    this.radGanttView1.GanttViewElement.Columns[3].Width = 120;
    this.radGanttView1.GanttViewElement.Columns[4].Width = 120;

    this.radGanttView1.GanttViewElement.GraphicalViewElement.TimelineRange = TimeRange.Month;
    this.radGanttView1.GanttViewElement.GraphicalViewElement.TimelineStart = new DateTime(2006, 8, 21);
    this.radGanttView1.GanttViewElement.GraphicalViewElement.TimelineEnd = new DateTime(2007, 4, 3);

}

private void radGanttView1_ItemChildIdNeeded(object sender, GanttViewItemChildIdNeededEventArgs e)
{
    int max = int.MinValue;
    foreach (DataRow row in (this.radGanttView1.DataSource as DataSet).Tables[0].Rows)
    {
        if (int.Parse(row[0].ToString()) > max)
        {
            max = int.Parse(row[0].ToString());
        }
    }
    e.ChildId = ++max;
}

1 comment
ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 15 Sep 2021 11:33

Hello, Yoann,

The possible solution that I can suggest is in addition to cancelling the ItemValidated event, you can cancel the edit operation:

        private void GanttViewElement_ItemValidating(object sender, GanttViewItemValidatingEventArgs e)
        {
            Debug.WriteLine("GanttViewElement_ItemValidating");
            Debug.WriteLine(e.Column.FieldName);
            e.Cancel = true;
            this.radGanttView1.GanttViewElement.CancelEdit();
        }

I hope this information helps.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.