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

Add Row to RadDataGrid in C#

3 Answers 150 Views
Grid for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Robert
Top achievements
Rank 1
Robert asked on 12 Jul 2013, 09:08 PM
I am writing to learn how best a row can be added dynamically, in C#, for a RadDataGrid being built out programmatically in C#;

Thanks in advance for any insight;

3 Answers, 1 is accepted

Sort by
0
Rosy Topchiyska
Telerik team
answered on 15 Jul 2013, 02:45 PM
Hello Robert,

Thank you for using our RadControls for Windows 8.

I have attached an example project demonstrating how to update your grid rows through the ItemsSource property of the grid. 

I hope this helps.


Regards,
Rositsa Topchiyska
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Robert
Top achievements
Rank 1
answered on 15 Jul 2013, 09:19 PM

Thanks for the feedback;
Working with the DataGridCellInfo, or similar, is it possible to populate a specific column/row cell;
The below code sample iterates thru a collection, and if the column title is changed - a new column is added;
The goal is to populate a cell, based on a column heading;
Thanks in advance for any insight;

 

 

for (int i = 0; i < scI; i++)
                    {
                        if (collectionScorecard[i].RegionName != columnTitle)
                        {
                            columnTitle = collectionScorecard[i].RegionName;
                            DataGridTextColumn textColumnRGN = new DataGridTextColumn() { PropertyName = "Metric", Header = columnTitle };                         
                            ScenariosNew.Columns.Add(textColumnRGN);
 
                             
 
                        }
                    }

 

 

 

 

0
Accepted
Rosy Topchiyska
Telerik team
answered on 16 Jul 2013, 11:35 AM
Hello Robert,

Thank you for your question.

Let me clarify how the RadDataGrid control works. The grid is not a spreadsheet - you cannot add arbitrary values in the cells. It needs a collection of business objects as an ItemsSource and each row of the grid corresponds to an item of this collection. The grid columns have to be bound to real properties of the business objects. If the column is bound to a nonexistent property, the cells in that column will be empty.

You can implement your custom logic for adding columns (on adding new object for example), but remember that the items in the ItemsSource collection correspond to a grid row, not to a single cell.

If you don’t know initially the properties of your objects, a possible solution is to use dynamic objects, but note that the schema of the grid will be determined by the properties of the first dynamic object in the collection. If the following objects have different properties, then the grid will not generate columns for these properties. Or if you add columns for the new properties, you will end up with empty cells for the objects that don't have such properties.

I hope this makes things clear and let us know if there is anything else we can assist you with.


Regards,
Rositsa Topchiyska
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Grid for XAML
Asked by
Robert
Top achievements
Rank 1
Answers by
Rosy Topchiyska
Telerik team
Robert
Top achievements
Rank 1
Share this question
or