Problem with Filtering

Apr 14, 2011 at 6:35 AM
Edited Apr 15, 2011 at 6:40 PM

I have a problem with Filtering,

I am using columns from another tables in grid like Department.Depname:

<sdk:DataGrid.Columns>
            <sdk:DataGridTextColumn  Header="ID" Binding="{Binding Id}"    Width="100" ></sdk:DataGridTextColumn>
            <sdk:DataGridTextColumn   Header="Name" Binding="{Binding Name}"  Width="200"></sdk:DataGridTextColumn>
            <sdk:DataGridTextColumn   Header="Address" Binding="{Binding Address}"  Width="200"></sdk:DataGridTextColumn>
            <sdk:DataGridTextColumn   Header="Phone" Binding="{Binding Phone}"  Width="100"></sdk:DataGridTextColumn>
            <sdk:DataGridTextColumn   Header="Department" Binding="{Binding Departments.DepName}" Width="100"></sdk:DataGridTextColumn>

        </sdk:DataGrid.Columns>

I build Entities like this:

 public class Departments
    {
        [Key]
        public int DepId { get; set; }
        public string DepName { get; set; }
        public bool IsDeleted { get; set; }

    }

 

public class Employees
    {
        [Key]
        public int Id { get; set; }
        public string Name { get; set; }
        public string Phone { get; set; }
        public string Address { get; set; }
        public int DepId { get; set; }
        public bool IsDeleted { get; set; }


        private Departments _departments;
        [Association("FK_Employees_Departments","DepId", "DepId", IsForeignKey = true)]
        public Departments Departments
        {
            get
            {
                return _departments;
            }
            set
            {
                _departments= value;
            }
        }
    }

 

Every column in Grid can filtered except Department this error showme:

Property 'Departments.DepName' is not defined for type 'EmpSilverlightApplication.Entities.Employees'

 

Please help me, Thank you very match

best regards

Coordinator
Apr 28, 2011 at 2:57 AM

Sorry for not seeing your question sooner.  I didn't get notified.  Anyways... the problem you are describing is a limitation of the grid.  Give me credit, I at least listed this on the main page :)  I have just relegated myself to creating a first level property which returns the nested property value.  I know I might be able to recurse throught the property path to get the property accessors, but could not come up with a clean way of doing it.  Sorry.. I wish I had a better answer for you.  In the end I just decided to live with this limitation.