How to dynamic add new column into radgridview

3 posts, 0 answers
  1. Owen
    Owen avatar
    2 posts
    Member since:
    Feb 2014

    Posted 12 Mar 2014 Link to this post

    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. Owen
    Owen avatar
    2 posts
    Member since:
    Feb 2014

    Posted 12 Mar 2014 Link to this post

    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
  3. DevCraft banner
  4. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 17 Mar 2014 Link to this post

    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.

     
Back to Top