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

Items Not Displaying in GanttView

4 Answers 80 Views
GanttView
This is a migrated thread and some comments may be shown as answers.
Robert Kaucher
Top achievements
Rank 2
Robert Kaucher asked on 11 Apr 2012, 09:20 PM
I have created the following GanttView in my XAML
<telerik:RadGanttView HorizontalAlignment="Left"
                             Name="radGanttView1"
                             VerticalAlignment="Top"
                             Width="950" Height="450"
                             TasksSource="{Binding ItProjects}"
                             telerik:StyleManager.Theme="Metro">
           <telerik:RadGanttView.Columns>
               <telerik:ColumnDefinition MemberBinding="{Binding Duration}" Header="Duration" ColumnWidth="100" />
               <telerik:ColumnDefinition MemberBinding="{Binding Start}" Header="Start" ColumnWidth="55" />
               <telerik:ColumnDefinition MemberBinding="{Binding End}" Header="End" ColumnWidth="55"/>
           </telerik:RadGanttView.Columns>
 
       </telerik:RadGanttView>


And I have the following code behind...
private ClientContext _ctx;
private IEnumerable<ListItem> _items;
private string _listName = "IT Projects";
private List<GanttTask> _itProjects;
public List<GanttTask> ItProjects
{
    get
    {
        if (_itProjects == null)
        {
            _itProjects = new List<GanttTask>();
        }
        return _itProjects;
    }
    set
    {
        if (_itProjects != value)
        {
            _itProjects = value;
            NotifyPropertyChanged("ItProjects");
        }
    }
}
 
 
 
public MainPage()
{
    InitializeComponent();
    _itProjects = new List<GanttTask>();
    GetItProjects();
    this.DataContext = this;
}
 
private void GetItProjects()
{
    _ctx = ClientContext.Current;
 
    CamlQuery camlQry = new CamlQuery()
    {
        ViewXml = "<View><Query><Where><Neq><FieldRef Name=\"Status\" /><Value Type=\"Choice\">Completed</Value></Neq></Where><OrderBy><FieldRef Name=\"Title\" Ascending=\"True\" /></OrderBy></Query></View>"
    };
    ListItemCollection listItems = _ctx.Web.Lists.GetByTitle(_listName).GetItems(camlQry);
 
    _items = _ctx.LoadQuery(listItems.Include(
            item => item["Title"],
            item => item.Id,
            item => item["StartDate"],
            item => item["DueDate"]
        ));
 
    _ctx.ExecuteQueryAsync(onQuerySucceeded, onQueryFailed);
}
 
private void onQuerySucceeded(object sender, ClientRequestSucceededEventArgs args)
{
 
    Dispatcher.BeginInvoke(() => {
        foreach (ListItem item in _items)
        {
            try
            {
                ItProjects.Add(ConvertListItemToProject(item));
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception: " + ex.Message + "Stack: "+ ex.StackTrace);
            }
        }
        NotifyPropertyChanged("ItProjects");
    });
}
 
private void onQueryFailed(object sender, ClientRequestFailedEventArgs args)
{
    //TODO: Set an error state.
    MessageBox.Show(args.ErrorDetails.ToString());
}
 
private GanttTask ConvertListItemToProject(ListItem item)
{
    TimeSpan ts = DateTime.Parse(item["StartDate"].ToString()) - DateTime.Parse(item["DueDate"].ToString());
     
    return new GanttTask(DateTime.Parse(item["StartDate"].ToString()), DateTime.Parse(item["DueDate"].ToString()), item["Title"].ToString());
}

I end up with 16 items in my collection but I see nothing in the control. Any suggestions? I've been experimenting with NotifyPropertyChanged in different places. I am not certain what the issue may be, though.

4 Answers, 1 is accepted

Sort by
0
Accepted
Miroslav Nedyalkov
Telerik team
answered on 12 Apr 2012, 08:04 AM
Hello Robert,

The problem in your code is that you create an empty list of items which doesn't rise change notifications (List<GanttTask>) and when your query finishes you don't replace the object and just rise the notification. As in your XAML you are binding the TasksSource dependency property to the view-model, it performs addition check and if the value haven't changed, no property changed notification is thrown inside the control and it doesn't update.

What I would suggest you is to either create a new list for the result or to use ObservableCollection instead of a simple List (this first one is preferable as it will perform better).

Hope this helps.

Kind regards,
Miroslav Nedyalkov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Robert Kaucher
Top achievements
Rank 2
answered on 12 Apr 2012, 01:20 PM
I used observable collection initially and I received this error.

http://www.telerik.com/community/forums/silverlight/ganttview/keynotfound.aspx 
0
Accepted
Miroslav Nedyalkov
Telerik team
answered on 12 Apr 2012, 02:57 PM
Hi Robert,

This was a bug which will be fixed in the 2012 Q2 release. In this case you could just change the way you work-around the issue using a new list just before throwing the notification.

Hope this helps.

All the best,
Miroslav Nedyalkov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Robert Kaucher
Top achievements
Rank 2
answered on 12 Apr 2012, 02:59 PM
Done! I was hoping that might have been fixed in an internal build but this is a really small project, so you suggestion is fine. Thanks!
Tags
GanttView
Asked by
Robert Kaucher
Top achievements
Rank 2
Answers by
Miroslav Nedyalkov
Telerik team
Robert Kaucher
Top achievements
Rank 2
Share this question
or