This is a migrated thread and some comments may be shown as answers.

Snapping per Day

3 Answers 72 Views
GanttView
This is a migrated thread and some comments may be shown as answers.
Ralf
Top achievements
Rank 2
Ralf asked on 08 Aug 2014, 11:07 AM
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.

3 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 13 Aug 2014, 09:09 AM
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.
 
0
Puffeltje
Top achievements
Rank 1
answered on 20 Jun 2015, 09:04 PM
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? 
0
Hristo
Telerik team
answered on 23 Jun 2015, 01:26 PM
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
Tags
GanttView
Asked by
Ralf
Top achievements
Rank 2
Answers by
George
Telerik team
Puffeltje
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or