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

How to dynamic add new column into radgridview

2 Answers 936 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Owen
Top achievements
Rank 1
Owen asked on 12 Mar 2014, 02:14 PM
Hello: guys


In my project, I have a GridView which has fixed columns and, according
to, collection of my objects, i have to add dynamically columns.

I can add dynamic columns but I can't access to each row and fill in the values ​​of each new column.


Each fixed column is binded to a property of my objects but dynamical
columns are not binded because their properties doesn't exist in my
objects.



So, how do I bind data for new column?


Regards,

Owen

2 Answers, 1 is accepted

Sort by
0
Owen
Top achievements
Rank 1
answered on 12 Mar 2014, 02:21 PM
Here are some code snippet

xaml

<Grid HorizontalAlignment="Stretch" Grid.Row="2" VerticalAlignment="Top">
            <telerik:RadGridView x:Name="ExampleRadGridView" GroupRenderMode="Flat"
                             IsFilteringAllowed="False"
                             AutoGenerateColumns="False"
                             CanUserFreezeColumns="True"
                             Height="500" Width="748"
                             ShowGroupPanel="False"
                             FrozenColumnCount="2">
                
                <telerik:RadGridView.Columns >
                    <telerik:GridViewDataColumn UniqueName="Column1"
                                            Header="Column 1"
                                            IsGroupable="False" />
                    <telerik:GridViewDataColumn UniqueName="Column2"
                                            Header="Column2"
                                            IsGroupable="False"
                                            Width="200" />
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
        </Grid>

CS

When page is loaded, I have attached the itemsource to ExampleRadGridView with a collection of Objects (Object 1).
When user clicks one check box. I need to add new column with different collection of Objects (Object 2).
Current I can add new column, but I don;t know how to fill in the value for new column.

Thanks
Owen
0
Yoan
Telerik team
answered on 17 Mar 2014, 04:02 PM
Hello Owen,

You can check the Defining Columns help article for a reference on how to define columns in the code-behind. For your convenience, I have attached a sample project showing you the approach.

Regards,
Yoan
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
Tags
GridView
Asked by
Owen
Top achievements
Rank 1
Answers by
Owen
Top achievements
Rank 1
Yoan
Telerik team
Share this question
or