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

Object Relational Hierarchy not working

3 Answers 88 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Menashay Givoni
Top achievements
Rank 1
Menashay Givoni asked on 02 Jun 2011, 02:49 AM

I am attempting to build hierarchy in a grid from business objects. If I select ‘Auto Generate Hierarchy’ and ‘Auto Generate Columns’ it does work.  Expanding a parent row shows its related children in RadGrid.

However, when I attempt to programmatically build the relation it does not work. Expanding a parent row does not show its related children.

I have followed the GridView Object Relational Hierarchy Mode documentation word for word without success.  I have used ‘property builder’ of the grid as per the tutorial but that did not help either.

Here is a sample code:

        private void FormEventStaffPlans_Load(object sender, EventArgs e)
        {
            // --------- Parent -----------
            // Staff plan unique identifier.
            GridViewDecimalColumn dColumn = new GridViewDecimalColumn("StaffPlanId");
            dColumn.HeaderText = "StaffPlanId";
            dColumn.IsVisible = false;
            dColumn.ReadOnly = true;
            this.radGridViewStaffPlans.Columns.Add(dColumn);
 
            // Total required staff.
            dColumn = new GridViewDecimalColumn("NumberOfStaffPerShift");
            dColumn.HeaderText = "Staff Req";
            this.radGridViewStaffPlans.Columns.Add(dColumn);
 
            // Total male
            dColumn = new GridViewDecimalColumn("NumberOfMalePerShift");
            dColumn.HeaderText = "Male";
            this.radGridViewStaffPlans.Columns.Add(dColumn);
 
            // Total female
            dColumn = new GridViewDecimalColumn("NumberOfFemalePerShift");
            dColumn.HeaderText = "Female";
            this.radGridViewStaffPlans.Columns.Add(dColumn);
 
            // Employee Id (TO DO: change this to dropdown box)
            dColumn = new GridViewDecimalColumn("EmployeeId");
            dColumn.HeaderText = "Empoloyee";
            this.radGridViewStaffPlans.Columns.Add(dColumn);
 
            // Labour hire company Id (TO DO: change this to dropdown list)
            dColumn = new GridViewDecimalColumn("HireCompanyId");
            dColumn.HeaderText = "HireCompanyId";
            this.radGridViewStaffPlans.Columns.Add(dColumn);
            this.radGridViewStaffPlans.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
 
            // --------- Child -----------
 
            // Create child template (for staff shifts)
            GridViewTemplate childTemplate = new GridViewTemplate();
            this.radGridViewStaffPlans.Templates.Add(childTemplate);
 
            // Set columns of child template
            // Shift unique identifier.
            dColumn = new GridViewDecimalColumn("ShiftId");
            dColumn.HeaderText = "ShiftId";
            dColumn.IsVisible = false;
            dColumn.ReadOnly = true;
            childTemplate.Columns.Add(dColumn);
 
            // Shift from (display date only).
            GridViewDateTimeColumn dtColumn = new GridViewDateTimeColumn("ShiftFrom");
            dtColumn.Format = DateTimePickerFormat.Short;
            dtColumn.HeaderText = "Date From";
            childTemplate.Columns.Add(dtColumn);
 
            // Shift to (display date only).
            dtColumn = new GridViewDateTimeColumn("ShiftTo");
            dtColumn.Format = DateTimePickerFormat.Short;
            dtColumn.HeaderText = "Date To";
            childTemplate.Columns.Add(dtColumn);
 
            // Shift from (display time only).
            dtColumn = new GridViewDateTimeColumn("ShiftFrom");
            dtColumn.Format = DateTimePickerFormat.Time;
            dtColumn.HeaderText = "Shift Start";
            childTemplate.Columns.Add(dtColumn);
 
            // Shift to (display time only).
            dtColumn = new GridViewDateTimeColumn("ShiftTo");
            dtColumn.Format = DateTimePickerFormat.Time;
            dtColumn.HeaderText = "Shift End";
            childTemplate.Columns.Add(dtColumn);
 
            // Shift part.
            dColumn = new GridViewDecimalColumn("ShiftPart");
            dColumn.HeaderText = "Shift Part";
            childTemplate.Columns.Add(dColumn);
 
            // Break duration.
            dColumn = new GridViewDecimalColumn("BreakDuration");
            dColumn.HeaderText = "Break Duration";
            childTemplate.Columns.Add(dColumn);
 
            // Variation code.
            GridViewTextBoxColumn tColumn = new GridViewTextBoxColumn("VariationCode");
            tColumn.HeaderText = "Variation Code";
            childTemplate.Columns.Add(tColumn);
 
            // Shift cost.
            dColumn = new GridViewDecimalColumn("ShiftCost");
            dColumn.HeaderText = "Shift Cost";
            dColumn.ReadOnly = true;
            childTemplate.Columns.Add(dColumn);
 
            // Shift cost type.
            tColumn = new GridViewTextBoxColumn("ShiftCostType");
            tColumn.HeaderText = "Shift Cost Type";
            dColumn.ReadOnly = true;
            childTemplate.Columns.Add(tColumn);
 
            // Area (TO DO: change this to dropdown list).
            dColumn = new GridViewDecimalColumn("AreaId");
            dColumn.HeaderText = "Area";
            childTemplate.Columns.Add(dColumn);
 
            // Shift type.
            tColumn = new GridViewTextBoxColumn("ShiftType");
            tColumn.HeaderText = "Shift Type";
            childTemplate.Columns.Add(tColumn);
 
            childTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
 
            // Add the relation between parent (staff plans) and the child (staff plan shifts)
            GridViewRelation relation = new GridViewRelation(this.radGridViewStaffPlans.MasterTemplate,                                 childTemplate);
            relation.ChildColumnNames.Add("EventShift");
            this.radGridViewStaffPlans.Relations.Add(relation);
 
            // Add data source to grid (parent).
            IList<EventStaffPlan> list = _siteProxy.GetEventStaffPlans(34);
            this.radGridViewStaffPlans.DataSource = list;
        }
 
 
    public class EventStaffPlan:BusinessObject
    {
        /// <summary>
        /// Default constructor for EventStaffPlan class.
        /// </summary>
        public EventStaffPlan() { }
        /// <summary>
 
        /// Overloaded constructor for EventStaffPlan class.
        /// Initialises automatic properties.
        /// </summary>
        /// <param name="staffPlanId">Staff plan unique identifier.</param>
        /// <param name="numberOfStaffPerShift">Total number of staff per shift.</param>
        /// <param name="numberOfMaleStaffPerShift">Number of male staff per shift.</param>
        /// <param name="numberOfFemaleStaffPerShift">Number of female staff per shift. </param>      
        /// <param name="employeeId">Employee unique identifier.</param>
        /// <param name="hireCompanyId">Hire company unique identifier.</param>
        /// <param name="eventShift">List of EventStaffShift objects.</param>
        public EventStaffPlan(int staffPlanId, int numberOfStaffPerShift, int numberOfMaleStaffPerShift,                int numberOfFemaleStaffPerShift, int employeeId, int hireCompanyId,             IList<EventStaffShift> eventShift)
        {
            StaffPlanId = staffPlanId;
            NumberOfStaffPerShift = numberOfStaffPerShift;
            NumberOfMalePerShift = numberOfMaleStaffPerShift;
            NumberOfFemalePerShift = numberOfFemaleStaffPerShift;          
            EmployeeId = employeeId;
            HireCompanyId = hireCompanyId;
            EventShift = eventShift;
        }
 
        /// <summary>
        /// Gets or sets staff plan unique identifier.
        /// </summary>
        public int StaffPlanId { get; set; }
 
        /// <summary>
        /// Gets or sets total number of staff per shift.
        /// </summary>
        public int NumberOfStaffPerShift { get; set; }
 
        /// <summary>
        /// Gets or sets number of male employees per shift.
        /// </summary>
        public int NumberOfMalePerShift { get; set; }
 
        /// <summary>
        /// Gets or sets number of female employees per shift.
        /// </summary>
        public int NumberOfFemalePerShift { get; set; }
 
        /// <summary>
        /// Gets or sets employee unique identifier.
        /// </summary>
        public int EmployeeId { get; set; }
 
        /// <summary>
        /// Gets or sets hire company unique identifier.
        /// </summary>
        public int HireCompanyId { get; set; }
 
        /// <summary>
        /// Gets or sets list of event staff plan shift objects.
        /// </summary>
        public IList<EventStaffShift> EventShift { get; set; }
    }



Class EventStaffShift does not have any related lists.
Working with version: 2011.1 11.419

3 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 07 Jun 2011, 03:28 PM
Hi Menashay,

I made a test using your scenario and did not find issues with manual setup of object-relational hierarchy mode. Here is a small example:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
   
    private void Form1_Load(object sender, EventArgs e)
    {
        GridViewTemplate template = new GridViewTemplate();
        radGridView1.Templates.Add(template);
 
        GridViewTextBoxColumn col = new GridViewTextBoxColumn("Model");
        template.Columns.Add(col);
 
        col = new GridViewTextBoxColumn("Price");
        template.Columns.Add(col);
 
        GridViewRelation relation = new GridViewRelation(radGridView1.MasterTemplate, template);
        relation.ChildColumnNames.Add("Cars");
        radGridView1.Relations.Add(relation);
 
        radGridView1.DataSource = Person.GetPersons();
    }
 
    public class Person
    {
        List<Car> cars = new List<Car>();
 
        public string Name { get; set; }
        public int Id { get; set; }
        public List<Car> Cars
        {
            get
            {
                return cars;
            }
        }
 
        public static BindingList<Person> GetPersons()
        {
 
            BindingList<Person> persons = new BindingList<Person>();
 
            Person person = new Person();
            person.Name = "John State";
            person.Id = 1;
            Car car = new Car();
            car.Model = "BMW 320d";
            car.Price = 44000;
            person.Cars.Add(car);
            persons.Add(person);
 
            person = new Person();
            person.Name = "Ivan Petrov";
            person.Id = 1;
            car = new Car();
            car.Model = "Lexus IS220";
            car.Price = 42000;
            person.Cars.Add(car);
            persons.Add(person);
 
            person = new Person();
            person.Name = "Evan Rotenberg";
            person.Id = 1;
            car = new Car();
            car.Model = "Audi A4";
            car.Price = 43500;
            person.Cars.Add(car);
            persons.Add(person);
 
            return persons;
        }
    }
 
    public class Car
    {
        public double Price { get; set; }
        public string Model { get; set; }
    }
}

Please review the attached screenshots for the result.

If you still experience any issues, please open a support ticket and send us a sample project which demonstrates them. This will allow us to provide you with a more helpful answer.

Greetings,
Julian Benkov
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
0
Menashay Givoni
Top achievements
Rank 1
answered on 08 Jun 2011, 12:30 AM
That is strange Julian.
I opened a support ticket for this issue and the Telerik team has confirmed that there is a bug in the Grid.
I copied & paste your code into a fresh new WinForms project but it did not work, see attached screenshot.
Perhaps you are using internal build with a fix to this bug?
0
Julian Benkov
Telerik team
answered on 10 Jun 2011, 03:55 PM
Hi Menashay,

Please accept my apologies for the omission. The problem is already resolved in the latest internal build v2011.1.11.510. As our customer, you can download this internal build from Your Account >> Download and Manage Your Products >> Telerik Premium Collection for .NET >> Download Installer and Other Resources >> RadControls for WinForms >> Latest Internal Builds.

I hope this helps.

Greetings,

Julian Benkov
the Telerik team

 

Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Tags
GridView
Asked by
Menashay Givoni
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Menashay Givoni
Top achievements
Rank 1
Share this question
or