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

[Solved] Obsolete FieldDescriptors

8 Answers 128 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.
Richard Harrigan
Top achievements
Rank 1
Richard Harrigan asked on 24 Jan 2011, 06:34 AM
I moved the following code to the latest version of RadGridView.  The commented lines do not compile because the FieldDescriptors are obsolete.  How do I change the obsolete code behind to the latest version of RadGridView.  For the base Table I changed RadGridView1.TableDefinition.FieldDescriptors.Add(gridViewDataColumn);
to
RadGridView1.Columns.Add(gridViewDataColumn);

I don't know how to Add GridViewDataColumn to the child tables?  Xaml is not an option.

Thanks
Rich
           


InitializeComponent();
           GridViewTableDefinition carDefinition = new GridViewTableDefinition();
           //carDefinition.AutoGenerateFieldDescriptors = false;
           gridViewDataColumn = new GridViewDataColumn();
           gridViewDataColumn.Header = "Car Name";
           gridViewDataColumn.DataMemberBinding = new Binding("CarName");
           gridViewDataColumn.DataType = Type.GetType("System.String");
           RadGridView1.Columns.Add(gridViewDataColumn);
           //RadGridView1.TableDefinition.FieldDescriptors.Add(gridViewDataColumn);
           gridViewDataColumn = new GridViewDataColumn();
           gridViewDataColumn.Header = "Year";
           gridViewDataColumn.DataMemberBinding = new Binding("Year");
           gridViewDataColumn.DataType = Type.GetType("System.Int32");
           RadGridView1.Columns.Add(gridViewDataColumn);
           //RadGridView1.TableDefinition.FieldDescriptors.Add(gridViewDataColumn);
           gridViewDataColumn = new GridViewDataColumn();
           gridViewDataColumn.Header = "Mileage";
           gridViewDataColumn.DataMemberBinding = new Binding("Mileage");
           gridViewDataColumn.DataType = Type.GetType("System.Int32");
           RadGridView1.Columns.Add(gridViewDataColumn);
           //RadGridView1.TableDefinition.FieldDescriptors.Add(gridViewDataColumn); 
           GridViewTableDefinition modelDefinition = new GridViewTableDefinition();
           //modelDefinition.AutoGenerateFieldDescriptors = false;
           //modelDefinition.FieldDescriptors.Add(new GridViewDataColumn() { Header = "Model Name", DataMemberBinding = new Binding("ModelName"), DataType = Type.GetType("System.String") });
           //modelDefinition.FieldDescriptors.Add(new GridViewDataColumn() { Header = "Horsepower", DataMemberBinding = new Binding("Horsepower"), DataType = Type.GetType("System.Int32") });
           //modelDefinition.FieldDescriptors.Add(new GridViewDataColumn() { Header = "Wheelbase", DataMemberBinding = new Binding("Wheelbase"), DataType = Type.GetType("System.Int32") });
           modelDefinition.Relation = new PropertyRelation("Models");
           RadGridView1.TableDefinition.ChildTableDefinitions.Add(modelDefinition);
           GridViewTableDefinition engineDefinition = new GridViewTableDefinition();
           //engineDefinition.AutoGenerateFieldDescriptors = false;
           //engineDefinition.FieldDescriptors.Add(new GridViewDataColumn() { Header = "Engine Name", DataMemberBinding = new Binding("EngineName"), DataType = Type.GetType("System.String") });
           //engineDefinition.FieldDescriptors.Add(new GridViewDataColumn() { Header = "Block ID", DataMemberBinding = new Binding("BlockID"), DataType = Type.GetType("System.String") });
           engineDefinition.Relation = new PropertyRelation("Engines");
           modelDefinition.ChildTableDefinitions.Add(engineDefinition);
           GridViewTableDefinition colorDefinition = new GridViewTableDefinition();
           //colorDefinition.AutoGenerateFieldDescriptors = false;
           //colorDefinition.FieldDescriptors.Add(new GridViewDataColumn() { Header = "Color Name", DataMemberBinding = new Binding("ColorName"), DataType = Type.GetType("System.String") });
           //colorDefinition.FieldDescriptors.Add(new GridViewDataColumn() { Header = "Trim Package", DataMemberBinding = new Binding("TrimPackage"), DataType = Type.GetType("System.String") });
           colorDefinition.Relation = new PropertyRelation("CarColors");
           modelDefinition.ChildTableDefinitions.Add(colorDefinition);

8 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 24 Jan 2011, 07:46 AM
Hi,

 You can use DataLoading event similar to this demo

Regards,
Vlad
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Richard Harrigan
Top achievements
Rank 1
answered on 26 Jan 2011, 01:09 AM
Hi,

I used the DataLoading event and that woked perfectivley.  I do however have another problem.  I used the following code to set GridViewRow.IsExpandable. 

private void RadGridView1_RowLoaded(object sender, RowLoadedEventArgs e)
        {
            GridViewRow row = e.Row as GridViewRow;
            var dataElement = e.DataElement;
  
            if (row != null && dataElement != null)
            {
                if (dataElement is Car)
                {
                    if (((Car)dataElement).Models.Count > 0)
                    {
                        row.IsExpandable = true;
                    }
                    else
                        row.IsExpandable = false;
                }
            }
        }

The problem is that I don't get a RowLoaded event for the child tables so that I can set the IsExpandable property.  I assume that the grid is working properly since the child tables are attached to the main table.  My class structure looks like the following:

Car
    Model
        Engine
        CarColor

I need to be able to set IsExpandable property for the Model class depending on the count being > 0 for the Engine and/or CarColor class.

Thanks
Rich

0
Veselin Vasilev
Telerik team
answered on 26 Jan 2011, 09:32 AM
Hi Richard Harrigan,

In this case you should define a HierarchyChildTemplate, put the child gridview there and subscribe to its RowLoaded event.

Hope this helps.

Kind regards,
Veselin Vasilev
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Richard Harrigan
Top achievements
Rank 1
answered on 26 Jan 2011, 06:15 PM
Hi,

The GridViewDataControl does not provide for the IsExpandable property.   Since this is a 3 level hierarchy I don't know how to set the IsExpandable property for Model.  If Model has either Engine or CarColor children show the + sign else show the - sign.  Also, this has to be accomplished in code-behind.

Car
      Model
            Engine
            CarColor

Thanks
Rich

0
Richard Harrigan
Top achievements
Rank 1
answered on 27 Jan 2011, 08:25 PM
I posed the previous question partially incorrect.  I don't want a minus when no childred a present. 

Thanks
Rich
0
Richard Harrigan
Top achievements
Rank 1
answered on 31 Jan 2011, 05:15 PM
Hi,

Is there a solution to this issue?  I need to know when child table is loading so I can set IsExpandable.

Thanks
Rich
0
Veselin Vasilev
Telerik team
answered on 01 Feb 2011, 03:37 PM
Hello Richard Harrigan,

I am a bit confused here.
"The GridViewDataControl does not provide for the IsExpandable property."
That is true, what I meant is that you can put a RadGridView in the HierarchyChildTemplate and subscribe to the RowLoaded event of that gridview. It will fire and you will have a reference to the rows of the child gridview.


Best wishes,
Veselin Vasilev
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Richard Harrigan
Top achievements
Rank 1
answered on 01 Feb 2011, 06:12 PM
Hi

Can you show me a how-to example in code-behind.  Xaml is not an option for me.

Thanks
Rich
Tags
GridView
Asked by
Richard Harrigan
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Richard Harrigan
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or