Snapping per Day

4 posts, 0 answers
  1. Ralf
    Ralf avatar
    8 posts
    Member since:
    May 2012

    Posted 08 Aug 2014 Link to this post

    How can i implement the behaviour that when a user edit´s a Task by moving start and end date the control only snaps every day.
  2. George
    Admin
    George avatar
    500 posts

    Posted 13 Aug 2014 Link to this post

    Hello Ralf,

    Thank you for writing.

    You can use the SelecteditemChanged event and subscribe to the PropertyChanged event of the selected item. Then, you can change its Start:
    this.GanttView.SelectedItemChanged += GanttView_SelectedItemChanged;
    ...
    GanttViewDataItem item;
    bool suspendChanged;
    void GanttView_SelectedItemChanged(object sender, GanttViewSelectedItemChangedEventArgs e)
    {
        if (item != null)
        {
            item.PropertyChanged -= item_PropertyChanged;
        }
     
        item = e.Item;
        if (item != null)
        {
            e.Item.PropertyChanged += item_PropertyChanged;
        }
    }
     
    void item_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        if (e.PropertyName == "Start" && !suspendChanged)
        {
            suspendChanged = true;
            item.Start = new DateTime(item.Start.Year, item.Start.Month, item.Start.Day);
            suspendChanged = false;
        }
     
    }

    I hope this helps.

    Regards,
    George
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Puffeltje
    Puffeltje avatar
    3 posts
    Member since:
    Jun 2015

    Posted 20 Jun 2015 in reply to George Link to this post

    It is a pitty that the answers are only for c++ or VB. I don't understand C++ but this solution is possibly also suitable for my problem. Can you translate this solution to VB? 
  5. Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 23 Jun 2015 Link to this post

    Hello Puffeltje,

    Thank you for writing.

    Please see below the VB version of the snippet of my colleague: 
    Private item As GanttViewDataItem
    Private suspendChanged As Boolean
     
    Sub New()
     
        InitializeComponent()
        AddHandler Me.RadGanttView1.SelectedItemChanged, AddressOf RadGanttView1_SelectedItemChanged
    End Sub
     
    Private Sub RadGanttView1_SelectedItemChanged(sender As Object, e As Telerik.WinControls.UI.GanttViewSelectedItemChangedEventArgs)
        If item IsNot Nothing Then
            RemoveHandler item.PropertyChanged, AddressOf item_PropertyChanged
        End If
     
        item = e.Item
        If item IsNot Nothing Then
            AddHandler e.Item.PropertyChanged, AddressOf item_PropertyChanged
        End If
    End Sub
     
    Private Sub item_PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs)
        If e.PropertyName = "Start" AndAlso Not suspendChanged Then
            suspendChanged = True
            item.Start = New DateTime(item.Start.Year, item.Start.Month, item.Start.Day)
            suspendChanged = False
        End If
    End Sub

    We also have a free online C# to VB and vice versa converter located here: http://converter.telerik.com/

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top