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

Can't binding data successfully.Help

1 Answer 24 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Neil Chow
Top achievements
Rank 1
Neil Chow asked on 02 Nov 2011, 10:36 PM
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;
        }
    }

1 Answer, 1 is accepted

Sort by
0
Jack
Top achievements
Rank 1
answered on 15 Dec 2011, 03:56 PM
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);
Tags
TreeListView
Asked by
Neil Chow
Top achievements
Rank 1
Answers by
Jack
Top achievements
Rank 1
Share this question
or