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

Hierarchical DataSet Question

14 Answers 146 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Don
Top achievements
Rank 1
Don asked on 23 Mar 2011, 09:31 PM
I am trying to set up a hierarchical RadGridView in my application. I have a function that returns a DataSet with two tables and a table relation directly from a SQL Server 2008 R2 database. However, I am unable to get the grid to display more than one table when trying to use the AutoGenerateHierarchy property. I see a reference to an AutoGenerateHierarchyFromDataSet property in the Binding to Hierarchical Data Automatically entry for the RadGridView control in the help, but I cannot locate this property in the control.

I need to do all of this in code, rather than graphically, due to several others using the same code base and having to dynamically connect to a database server and database at runtime. In this instance, dynamically can also be taken to mean that the server and database names are filled in from a configuration file at application launch.

14 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 25 Mar 2011, 10:14 AM
Hello Don,

Please take a look at the Demos application under: GridView -> Hierarchy -> Hierachy First Look -> and in the right scenarios: Auto generated from data set.

Please take a look at that example and if everything is set up the same in your code please take a look at the relations provided in the dataset.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Don
Top achievements
Rank 1
answered on 25 Mar 2011, 03:44 PM
My setup is different as I am doing late-binding to the data from data source information in a configuration file. I cannot set up the data source at design time, it must be done at run time. It would be nice if I could use a Binding Source object and fill Table Adapters, but that is not part of the specification I have to work with.

I looked at the API for the GridView control, but there is not enough information given to allow me to do more than make haphazard guesses as to what each property and method does and the types of parameters needed for each. Telerik did a great job on the basic documentation, but not so good on the low-level stuff.
0
Emanuel Varga
Top achievements
Rank 1
answered on 26 Mar 2011, 05:45 PM
Hello again Don,

I don't really know i can help you without knowing with what are you working with and where you need to end up, but if you could provide a small sample project i would be more than happy to help you further.

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 26 Mar 2011, 06:19 PM
Hello Don,

As Emanuel has mentioned, some sort of sample would help. But in the meantime, perhaps you are referring to Load On Demand which will allow you to load the child view as you click to expand a parent row. If this is the case, please take a look at this help topic which will guide you through that subject.

Hope that helps, but let me know if you need further advice
Richard
0
Don
Top achievements
Rank 1
answered on 29 Mar 2011, 02:57 PM
That is close to what I need, Richard, but not quite there. I was hoping to be able to give the grid all of the table and relationship data and have it generate the parent and child grids for me, but this has not been the case. I will use the unbound example as a starting point and go from there. Thank you for your efforts.
0
Richard Slade
Top achievements
Rank 2
answered on 29 Mar 2011, 03:12 PM
Hello Don,

Please have a look at this help topic on AutoGenerateHierarchyFromDataSet which I think you will find of benefit.
Hope that helps
Richard
0
Don
Top achievements
Rank 1
answered on 29 Mar 2011, 08:37 PM
I got things to work, but I had to code everything myself. The grid's reliance on the visual data tools in the IDE (binding sources and table adapters in particular) is a bit of a downer, but not insurmountable.

It seems that if you are not using a table adapter, which you can only do if you use the visual data tools at design time, the gridview cannot ferret out your table structure. That is why I ended up defining all of my gridview templates and their columns in code. Now that I've done it once it will be much easier to do in the future.
0
Richard Slade
Top achievements
Rank 2
answered on 29 Mar 2011, 10:31 PM
Hi Don,

I'm not sure if you've seen all the help topics on auto generating hierarchies. You can also auto generate them from object relational hierarchies too. More info is here.

Hope you find this if interest.
Richard
0
Julian Benkov
Telerik team
answered on 01 Apr 2011, 09:07 AM
Hello Don,

I suppose that your requirement is to bind RadGridView programmatically. If this is your case, you should set the AutoGenerateHierarchy property to true and setup DataSource to your DatSet and DataMember to your root table. Please keep in mind that in this scenario you must define DataRelation between your DataTables. Here is a small example:

Random rand = new Random();
DataTable table = new DataTable("Data1");
table.Columns.Add("ID", typeof(int));
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Value", typeof(int));
 
for (int i = 0; i < 5; i++)
{
    table.Rows.Add(i, "Row " + i, rand.Next(10));
}
 
DataTable table2 = new DataTable("Data2");
table2.Columns.Add("ID", typeof(int));
table2.Columns.Add("ParentID", typeof(int));
table2.Columns.Add("Value", typeof(int));
table2.Columns.Add("Check", typeof(bool));
int parentId = 0;
for (int i = 0; i < 100; i++)
{
    table2.Rows.Add(i, parentId, rand.Next(5), false);
    parentId++;
    if (parentId == 5)
    {
        parentId = 0;
    }
}
 
DataSet set = new DataSet();
set.Tables.Add(table);
set.Tables.Add(table2);
set.Relations.Add(new DataRelation("rel1", table.Columns[0], table2.Columns[1]));
 
gridView.AutoGenerateHierarchy = true;
gridView.DataMember = "Data1";
gridView.DataSource = set;

I hope this helps. If this is still not your case, I would kindly ask you for additional details. This will allow us to provide you with an adequate response and improve our documentation accordingly.

Greetings,
Julian Benkov
the Telerik team
0
Don
Top achievements
Rank 1
answered on 01 Apr 2011, 06:39 PM
'setup the master template columns
entityIDColumn.DecimalPlaces = 0
entityIDColumn.IsVisible = False
Me.grdSearchResults.MasterTemplate.Columns.Add(entityIDColumn)
 
nameColumn.HeaderText = "Name"
Me.grdSearchResults.MasterTemplate.Columns.Add(nameColumn)
 
dobColumn.FormatString = "{0: MM/dd/yyyy}"
dobColumn.TextAlignment = ContentAlignment.MiddleCenter
dobColumn.HeaderText = "Date of Birth"
Me.grdSearchResults.MasterTemplate.Columns.Add(dobColumn)
 
'Expands column widths equally to fill the grid
Me.grdSearchResults.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill
 
'EnableGrouping is set to True by default and we didn't want grouping
Me.grdSearchResults.EnableGrouping = False
 
'setup the child template columns
eIDColumn.DecimalPlaces = 0
eIDColumn.IsVisible = False
template.Columns.Add(eIDColumn)
 
matterIDColumn.DecimalPlaces = 0
matterIDColumn.IsVisible = False
template.Columns.Add(matterIDColumn)
 
caseNumberColumn.HeaderText = "Case Number"
template.Columns.Add(caseNumberColumn)
 
dateColumn.HeaderText = "Date"
dateColumn.FormatString = "{0: MM/dd/yyyy}"
dateColumn.TextAlignment = ContentAlignment.MiddleCenter
template.Columns.Add(dateColumn)
 
roleColumn.HeaderText = "Role"
template.Columns.Add(roleColumn)
 
topCountColumn.HeaderText = "Top Count"
template.Columns.Add(topCountColumn)
 
caseStatusColumn.HeaderText = "Case Status"
template.Columns.Add(caseStatusColumn)
 
caseTypeColumn.HeaderText = "Case Type"
template.Columns.Add(caseTypeColumn)
 
'Expands column widths equally to fill the grid
template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill
 
'Adds child template to the Templates collection of the Master template
Me.grdSearchResults.MasterTemplate.Templates.Add(template)
 
'grdSearchResults Relation definition
radRelation = New GridViewRelation(Me.grdSearchResults.MasterTemplate, template)
radRelation.RelationName = "EntityMatter"
radRelation.ParentColumnNames.Add("EntityID")
radRelation.ChildColumnNames.Add("EntityID")
Me.grdSearchResults.Relations.Add(radRelation)
 
Me.grdSearchResults.AutoGenerateHierarchy = False 'True didn't work when setting the DataMember to t_Entity
Me.grdSearchResults.DataSource = mDataSet
Me.grdSearchResults.MasterTemplate.DataSource = mDataSet.Tables("t_Entity")
template.DataSource = mDataSet.Tables("t_Matter")

This is what I ended up doing to get my hierarchy to work. I had tried setting the DataMember to my t_Entity table and setting AutoGenerateHierarchy to True, but it did not generate the child relations. So I set the DataSources for the templates directly to the tables used in the Relation, set AutoGenerateHierarchy to False and it worked.

The comments are for me when I go back and look at this in six months so I can see what I was thinking at the time.
0
Julian Benkov
Telerik team
answered on 07 Apr 2011, 08:32 AM
Hi Don,

I am glad to hear that you have solved your issue.

This is another way to setup hierarchy using manually added GridViewTemplates and Relations and not using the AutoGenerateHierarchy property.

All the best,

Julian Benkov
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
Zadros
Top achievements
Rank 1
answered on 26 May 2011, 02:24 AM
I am using a DataSet with two DataTables, I created a relation between them but when I see the GridView the main records dont have children.

DataTable oMovs = this.pagos.Clone();
oMovs.TableName = "movimientos";
DataTable oDeps = this.pagos.Clone();
oDeps.TableName = "dependientes";
 
// Code to split the information from a single DataTable
 
DataSet oDataSet = new DataSet();
oDataSet.Tables.Add(oMovs);
oDataSet.Tables.Add(oDeps);
oDataSet.Relations.Add(new DataRelation("depende", oMovs.Columns["movimientoContratoDetalleID"]
    , oDeps.Columns["movimientoOrigenID"]));
 
this.radPagos.AutoGenerateHierarchy = true;
this.radPagos.DataMember = "movimientos";
this.radPagos.DataSource = oDataSet;


I have tried using a GridViewTemplate and a GridViewRelation, tried setting AutoGenerateHierarchy to false and assigning the DataSource directly (it throws an error of null argument, dont know why) and nothing seems to work.
The GridView has a group but I removed it and it still won't associate the parents with their children.
Any suggestion? Am I missing something?
0
Don
Top achievements
Rank 1
answered on 27 May 2011, 09:17 PM
I had to explicitly create a GridViewRelation even though my dataset had a relation defined within it.
0
Julian Benkov
Telerik team
answered on 31 May 2011, 08:37 AM
Hi Zadros,

You can try to manually setup the hierarchy for your scenario like Don suggested:

DataTable oMovs = this.pagos.Clone();
oMovs.TableName = "movimientos";
DataTable oDeps = this.pagos.Clone();
oDeps.TableName = "dependientes";
  
// Code to split the information from a single DataTable
  
DataSet oDataSet = new DataSet();
oDataSet.Tables.Add(oMovs);
oDataSet.Tables.Add(oDeps);
oDataSet.Relations.Add(new DataRelation("depende", oMovs.Columns["movimientoContratoDetalleID"]
    , oDeps.Columns["movimientoOrigenID"]));
  
this.radPagos.AutoGenerateHierarchy = false;
this.radPagos.DataSource = oMovs;
 
GridViewTemplate template = new GridViewTemplate();
template.DataSource = oDeps;
this.radPagos.Templates.Add(template);
 
GridViewRelation relation = new GridViewRelation(this.radPagos.MasterTemplate, template);
relation.ParentColumnNames.Add("movimientoContratoDetalleID");
relation.ChildColumnNames.Add("movimientoOrigenID");
relation.RelationName = "MovsDeps";
this.radPagos.Relations.Add(relation);

I hope you find this information useful. Let me know if you need further assistance.

Regards,
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
Don
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Don
Top achievements
Rank 1
Richard Slade
Top achievements
Rank 2
Julian Benkov
Telerik team
Zadros
Top achievements
Rank 1
Share this question
or