Items Not Displaying in GanttView

5 posts, 2 answers
  1. Robert Kaucher
    Robert Kaucher avatar
    56 posts
    Member since:
    Oct 2010

    Posted 11 Apr 2012 Link to this post

    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.
  2. Answer
    Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 12 Apr 2012 Link to this post

    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 >>

  3. DevCraft banner
  4. Robert Kaucher
    Robert Kaucher avatar
    56 posts
    Member since:
    Oct 2010

    Posted 12 Apr 2012 Link to this post

    I used observable collection initially and I received this error.

    http://www.telerik.com/community/forums/silverlight/ganttview/keynotfound.aspx 
  5. Answer
    Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 12 Apr 2012 Link to this post

    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 >>

  6. Robert Kaucher
    Robert Kaucher avatar
    56 posts
    Member since:
    Oct 2010

    Posted 12 Apr 2012 Link to this post

    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!
Back to Top
DevCraft banner