Can't binding data successfully.Help

2 posts, 0 answers
  1. Neil Chow
    Neil Chow avatar
    4 posts
    Member since:
    Dec 2009

    Posted 02 Nov 2011 Link to this post

    Here is XML code:                 
       <telerik:RadTreeListView x:Name="myDataGrid"  RowActivated="myDataGrid_RowActivated" 
    AutoGenerateColumns="False" IsReadOnly="True" 
                                     CanUserFreezeColumns="False"  Height="600" AutoLoadHierarchy="False" RowIndicatorVisibility="Collapsed">
                            <telerik:RadTreeListView.ChildTableDefinitions>
                                <telerik:TreeListViewTableDefinition ItemsSource="{Binding FormItems}" />
                            </telerik:RadTreeListView.ChildTableDefinitions>
                            <telerik:RadTreeListView.Columns>
                                <telerik:GridViewDataColumn TextAlignment="Left"  DataMemberBinding="{Binding ReportName}" Header="Report Name" Width="140"/>
                                <telerik:GridViewDataColumn DataMemberBinding="{Binding ReportNumber}" Header="Report Number" Width="140"/>
                                <telerik:GridViewDataColumn DataMemberBinding="{Binding Status}" Header="Status" Width="140"/>
                                <telerik:GridViewDataColumn DataMemberBinding="{Binding Date_Created}" Header="Date Created" Width="140"/>
                                <telerik:GridViewDataColumn DataMemberBinding="{Binding UserID}" Header="User Name" Width="140"/>
                                <!--<telerik:GridViewDataColumn Header="Reserve" Width="140"/>-->
                            </telerik:RadTreeListView.Columns>
                        </telerik:RadTreeListView >   
    In ViewModel:
            private ObservableCollection<FormItem> _formitems;
            public ObservableCollection<FormItem> FormItems
            {
                get { return _formitems; }
                set
                {
                    _formitems = value;
                    RaisePropertyChanged("FormItems");
                }
            }

    Here is FormItem Class code:          
     public class FormItem
        {
            public FormItem(Report _formitem)
            {
                this.ReportName =_formitem.ReportName ;
                this.ReportNumber = _formitem.ReportNumber;
                this.Status = _formitem.Status;
                this.Date_Created = _formitem.Date_Created;
                this.UserID = _formitem.UserID;
                this.ID = _formitem.ID;
                this.Items = new ObservableCollection<FormItem>();
            }
            public ObservableCollection<FormItem> Items
            {
                get;
                set;
            }


            public String ReportName
            {
                get;
                set;
            }
            public String ID
            {
                get;
                set;
            }


            public String ReportNumber
            {
                get;
                set;
            }


            public int Status
            {
                get;
                set;
            }
            public DateTime Date_Created
            {
                get;
                set;
            }


            public string UserID
            {
                get;
                set;
            }
        }
  2. Jack
    Jack avatar
    14 posts
    Member since:
    Sep 2011

    Posted 15 Dec 2011 Link to this post

    Hey,

    I'm also currently working with TreeListView.

    I may or may not be right. But I see that you are binding the ChildTable to FormItems, which is a collection of FormItem. However in your FormItem class, you do not have a collection called FormItems, instead you only have Items.

    Here is my understanding of how this TreeListview works, you need to bind your datacontext of the app to an observable collection of some class(in your case FormItem) and in each instance of FormItem in your collection, you need a collection of the same class that should be binded to the ChildTable.


    Try binding the child table to Items (which is a collection that exist in your class);
  3. DevCraft banner
Back to Top