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

[Solved] Self-referencing

2 Answers 92 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
jay
Top achievements
Rank 1
jay asked on 13 Jun 2010, 12:17 AM
Hi, I have been trying to get a piece of code I got off your self-referencing demo to work under a slightly different situation.
I am using a database that has (like in the AdventureWorks database) a different table that stores the names of the employees. So I use a view to populate my datagrid to show all the fields I need to see on the grid. My problem is in knowing which rows have direct reports.
I tried using the code below, but each time i get the following error message in the HasSubordinates block:

System.InvalidCastException was unhandled by user code
  Message=Unable to cast object of type 'System.Windows.Controls.DomainDataSourceView' to type 'System.Collections.Generic.IEnumerable`1[SLightBizApp.Web.vw_Employee]'.

        private void RadGridViewEmp_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)

        {

            GridViewRow row = e.Row as GridViewRow;

            vw_Employee employee = e.DataElement as vw_Employee;

            if (row != null && employee != null)

            {

                row.IsExpandable = this.HasSubordinates(employee);

            }            

        }

        private bool HasSubordinates(vw_Employee employee)

        {        

            return

            (from emp in (IEnumerable<vw_Employee>)this.RadGridViewEmp.ItemsSource

             where emp.ReportsToID == employee.EmployeeID

             select emp).Any();

        }

------------------------------------------------------------------------------------

Any pointers?

Thanks

J


2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 14 Jun 2010, 07:19 AM
Hi,

 The exception says that you cannot cast DomainDataSourceView (the grid ItemsSource) to IEnumerable<vw_Employee>. You can find more info about DomainDataSourceView here.

Kind regards,
Vlad
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
kannan
Top achievements
Rank 1
answered on 04 Oct 2010, 10:39 AM
Hi,
     You can use table instead of view ....it is working...

 private bool HasSubordinates(tableName employee)

        {        

            return

            (from emp in (IEnumerable<tablename>)this.RadGridViewEmp.ItemsSource

             where emp.ReportsToID == employee.EmployeeID

             select emp).Any();

        }

Tags
GridView
Asked by
jay
Top achievements
Rank 1
Answers by
Vlad
Telerik team
kannan
Top achievements
Rank 1
Share this question
or