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

Add a Column to an existing DetailTable via the code behind

6 Answers 243 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bruno
Top achievements
Rank 1
Bruno asked on 18 Feb 2009, 06:37 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

6 Answers, 1 is accepted

Sort by
0
Boone
Top achievements
Rank 2
answered on 18 Feb 2009, 07:19 PM
GridBoundColumn boundColumn; 
boundColumn = new GridBoundColumn(); 
RadGrid1.MasterTableView.Columns.Add(boundColumn); 
boundColumn.DataField = "valor"
boundColumn.HeaderText = "valor";
boundColumn.UniqueName = "valor"
boundColumn.DataFormatString = "{0:R$###,###.##}";

 
GridTableView tableViewOrders = new GridTableView(RadGrid1); 

That should do what you are wanting.
0
Bruno
Top achievements
Rank 1
answered on 18 Feb 2009, 08:23 PM
Boone
In this code you are creating a new GridTableView.

GridTableView tableViewOrders = new GridTableView(RadGrid1);  

What I want to do is to Append a new Column in to a first level existing Detail Table.

or some way to create all columns in the ASPx file and after that starting to hide columns depending on logged user.




0
Boone
Top achievements
Rank 2
answered on 18 Feb 2009, 08:30 PM
This is the piece that does the trick. That last line was something else I was playing with and forgot to remove it for your problem.

RadGrid1.MasterTableView.Columns.Add(boundColumn);  

0
Bruno
Top achievements
Rank 1
answered on 18 Feb 2009, 09:04 PM
I Already have this line take a look again in my piece of code.

                GridBoundColumn boundColumn;  
                boundColumn = new GridBoundColumn();  
                RadGrid1.MasterTableView.Columns.Add(boundColumn);  
                boundColumn.DataField = "valor";  
                boundColumn.HeaderText = "Valor";  
                boundColumn.UniqueName = "valor";  
                boundColumn.DataFormatString = "{0:R$###,###.##}";  

This line do the work just for the root level, this one will add a column in to MASTER TABLE

I Need to add a column into DetailTable.

something like
                RadGrid1.MasterTableView.DetailTable.Columns.Add(boundColumn); 
(but that doenst work as well..)

0
Accepted
Boone
Top achievements
Rank 2
answered on 18 Feb 2009, 09:25 PM
RadGrid1.MasterTableView.DetailTables[0].Columns.Add( boundColumn); ?

0
Bruno
Top achievements
Rank 1
answered on 18 Feb 2009, 09:56 PM
PERFECT!!

This works fine !!

Thank you Boone

                GridBoundColumn boundColumn; 
                boundColumn = new GridBoundColumn(); 
                RadGrid1.MasterTableView.Columns.Add(boundColumn); 
                boundColumn.DataField = "valor"
                boundColumn.HeaderText = "Valor"
                boundColumn.UniqueName = "valor"
                boundColumn.DataFormatString = "{0:R$###,###.##}"
 
 
 
                GridBoundColumn boundColumn1; 
                boundColumn1 = new GridBoundColumn(); 
                                  
              RadGrid1.MasterTableView.DetailTables[0].Columns.Add(boundColumn1); 
                boundColumn1.DataField = "valor"
                boundColumn1.HeaderText = "Valor"
                boundColumn1.UniqueName = "valor"
                boundColumn1.DataFormatString = "{0:R$###,###.##}"
Tags
Grid
Asked by
Bruno
Top achievements
Rank 1
Answers by
Boone
Top achievements
Rank 2
Bruno
Top achievements
Rank 1
Share this question
or