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

how add data in code-behind without binding

2 Answers 413 Views
GridView
This is a migrated thread and some comments may be shown as answers.
smr
Top achievements
Rank 1
smr asked on 07 Dec 2019, 06:54 AM

Hello

how can i add columns and rows and cells just by code-behind without use binding

(i need to do this in loop)

and i use telerik 2019 noxaml

Thanks ♥

 

 

2 Answers, 1 is accepted

Sort by
0
smr
Top achievements
Rank 1
answered on 10 Dec 2019, 09:12 AM

hi again

i use this code

this work just for columns

but doesn't work for rows and cells

 

            for (int i = 0; i < 10; i++)
            {
                GridViewColumn grid_Column = new GridViewColumn();
                grid_Column.Header = "num : " + i;
                grid_Column.Width = 20;
                grid_Column.Name = "column" + i.ToString();
                view.Columns.Add(grid_Column);
            }
            GridViewRow[] item_v = new GridViewRow[size[1]];
            for (int i = 0; i < 10; i++)
            {
                item_v[i] = new GridViewRow();
                for (int j = 0; j < 10; j++)
                {
                    GridViewCell cell = new GridViewCell();
                    cell.Content = ((i + 1) * (j + 1)).ToString();
                    item_v[i].Cells.Add(cell);
                }
                view.Items.AddNewItem(item_v);
            }

0
Vladimir Stoyanov
Telerik team
answered on 11 Dec 2019, 12:28 PM

Hello,

Thank you for the shared code snippet. 

Please, allow me to start by saying that the RadGridView is designed to be a databound control and as such there isn't a way to populate individual cells in code. The rows in the RadGridView display one object from its ItemsSource and each cell shows the value of one property of that object. With this in mind, you can create a collection of some object and bind it to the ItemsSource of the RadGridView as demonstrated in the Getting Started article. 

On a side note, you can also check out the RadVirtualGrid, which is a more light-weight grid version, but with less features than the RadGridView. That said, it allows for populating its cells in a manner similar to what you are going for. 

I hope this helps.

Regards,
Vladimir Stoyanov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
smr
Top achievements
Rank 1
Answers by
smr
Top achievements
Rank 1
Vladimir Stoyanov
Telerik team
Share this question
or