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

programmatically create schema and fill the gridview rows

4 Answers 422 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Meisam
Top achievements
Rank 1
Meisam asked on 18 Jul 2009, 01:09 PM
respectfully,
i want to programmatically create a custom schema (create columns in custom without binding) and fill the gridview with custom data ( add new rows without binding )! I found that the wpf radgridview do not have the rows collection and it seems that is necessary to bind radgridview to a data source for displaying data, but i want to add new rows and columns programatically at run time even if i bound it to data source before! is there any approach for this purpose?!
thanks for your kindness ;)

4 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 19 Jul 2009, 10:09 AM
Hi Meisam,

Currently the grid does not support unbound mode but there is a workaround that might work for your scenario. You can bind the grid to an empty observable collection and add your items to that collection, instead of directly adding the items to the grid.

RadGridView has a collection called Columns which you can use to add/remove columns prgramatically.

I have created a sample to illustrate that scenario.

Greetings,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Meisam
Top achievements
Rank 1
answered on 19 Jul 2009, 01:10 PM
thank you so much,

that's  nice for master tables, but in hierarchy custom approach, how can i modify the child table schema? for example, it bounded to some collection (child collection of the master collection) that i don't want to display some properties of that.

i hope my explanation was clear.
Kind regards
0
Milan
Telerik team
answered on 23 Jul 2009, 06:32 AM
Hello Meisam,

Thre is not problem to show a subset of the original properties in a child grid. You just need to provide a new HierarchyChildTemplate, which is a piece of cake.Since you are using 2009.1.526 version of RadGridView you have to do a little bit more work due to some issues in the grid.

I have updated the sample application which now displays only one column in a child grid for an object that has many properties.

If you decide to upgrade to our latest version (Q2) you will be able to achive the same effect without any code behind - you will only need to do something like that:

<telerik:RadGridView Name="RadGridView1">  
    <telerik:RadGridView.HierarchyChildTemplate> 
        <DataTemplate> 
            <telerik:GridViewDataControl AutoGenerateColumns="False">  
        <!-- Choose which columns will be displayed in child grids--> 
                <telerik:GridViewDataControl.Columns> 
                    <telerik:GridViewDataColumn DataMemberPath="Memo2"/>  
                </telerik:GridViewDataControl.Columns> 
            </telerik:GridViewDataControl> 
        </DataTemplate> 
    </telerik:RadGridView.HierarchyChildTemplate> 
</telerik:RadGridView> 

Hope this helps.

Kind regards,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Meisam
Top achievements
Rank 1
answered on 26 Jul 2009, 05:45 AM
Hi Milan,
Thanks a lot,

because I have multiple child definitions, I think I can't use this approach. Currently I implement that in this way:
GridViewDataColumn columnCI_NAME = new GridViewDataColumn();  
columnCI_NAME.DataMemberBinding = new Binding("CI_NAME");  
columnCI_NAME.HeaderText = "CI NAME";  
detailDefinition.FieldDescriptors.Add(columnCI_NAME); 

for each child definition.

I will be happy if i know your idea,
Best Wishes
Tags
GridView
Asked by
Meisam
Top achievements
Rank 1
Answers by
Milan
Telerik team
Meisam
Top achievements
Rank 1
Share this question
or