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

Hierarchical Grid-Add GridTableView programatically

3 Answers 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Omlac
Top achievements
Rank 1
Omlac asked on 06 Oct 2008, 11:19 AM

i would like to develop a hierarchical grid view programmatically. The firstrow(masterTableview) im adding it at design time.
Im doing that using the code below, but its not adding the griddesignview(children for the first row) Does anyone see whats wrong with the code im using here:
Master.ParentlocationID is matched to TableView.LocationID, im also using a dataset as my datasource.

 

adapter.Fill(dsData);

 

 

 

 

 

GridTableView tableSubLocation = new GridTableView(rdgLocation);

 

rdgLocation.MasterTableView.DetailTables.Add(tableSubLocation);

tableSubLocation.DataSource = dsData;

 

 

 

 

 

tableSubLocation.Width =

 

 

 

 

Unit.Percentage(100);

 

 

 

 

 

 

GridRelationFields relationFields = new GridRelationFields();

 

tableSubLocation.ParentTableRelation.Add(relationFields);

relationFields.MasterKeyField =

 

 

 

 

"LocationID";

 

relationFields.DetailKeyField =

 

 

 

 

"ParentLocationID";

 

 

 

 

 

 

GridBoundColumn boundColumn;

 

boundColumn =

 

 

 

 

new GridBoundColumn();

 

tableSubLocation.Columns.Add(boundColumn);

boundColumn.DataField =

 

 

 

 

"LocationID";

 

boundColumn.HeaderText =

 

 

 

 

"LocationID";

 

boundColumn =

 

 

 

 

new GridBoundColumn();

 

tableSubLocation.Columns.Add(boundColumn);

boundColumn.DataField =

 

 

 

 

"Location";

 

boundColumn.HeaderText =

 

 

 

 

"Location";

 

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 06 Oct 2008, 01:32 PM
Hi Omlac,

"RadGrid does not support mixing declarative grid columns with grid columns added dynamically at runtime. You should either create all the columns in the grid programmatically, or else define them all in the ASPX file."

Check out the link below for more information on programmatic creation of hierarchial grid.

http://www.telerik.com/help/aspnet-ajax/grdprogrammaticcreation.html

Thanks,
Princy

0
Omlac
Top achievements
Rank 1
answered on 06 Oct 2008, 01:54 PM
Thank you very much,
 Im sorry for the format of my message
0
Bruno
Top achievements
Rank 1
answered on 18 Feb 2009, 06:35 PM
Hello,

and what if I want to programmatic add a new column to an existing Detail Table?

something like that.

<MasterTableView> 
   <detailtables> 
        <Gridtableview> 
 
            <columns> 
              <gridboundcolumn></gridboundcolumn
              <gridboundcolumn></gridboundcolumn
              <gridboundcolumn></gridboundcolumn
 
                How to insert more columns here, using the code behind? 
 
            <columns> 
        <gridtableview> 
 
   </detailtables> 
 
<columns>......</columns> 
<MastertableView> 

I used this successfully to add to the master table, but I cant add to the detail table.

                GridBoundColumn boundColumn; 
                boundColumn = new GridBoundColumn(); 
                RadGrid1.MasterTableView.Columns.Add(boundColumn); 
                boundColumn.DataField = "valor"
                boundColumn.HeaderText = "Valor"
                boundColumn.UniqueName = "valor"
                boundColumn.DataFormatString = "{0:R$###,###.##}"
How can I do the same with DETAILTABLES ?????

Thanxs
Tags
Grid
Asked by
Omlac
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Omlac
Top achievements
Rank 1
Bruno
Top achievements
Rank 1
Share this question
or