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

How to bind nested generic list to radGridView?

4 Answers 134 Views
GridView
This is a migrated thread and some comments may be shown as answers.
hosein
Top achievements
Rank 1
hosein asked on 11 Jun 2011, 12:36 PM

Hello

I' going to Load Data from a nested generic list and Bind it to a radGridView. But I could not do that

this is my list:

List<List<string>> Mylist = new List<List<string>>();
and I add items into the list like below:

Mylist.Add(new List<string> { str1, str2, str3 });
at the end I set the gridview dataSource like this:

DGV1.DataSource = Mylist;
But it does not show the data from the list. the grid has 2 columns: Capacity, Count

Does anyone knows How I can Bind Mylist to the grid?

thanks

4 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 15 Jun 2011, 01:45 PM
Hello hosein,

You can not bind primitive types such as string array directly to RadGridView control. For you scenario you can use unbound mode of grid to get/set string values:

Random r = new Random();
this.radGridView1.ColumnCount = 10;
this.radGridView1.RowCount = 30;
 
//set values
using (this.radGridView1.DeferRefresh())
{
    for (int i = 0; i < this.radGridView1.RowCount; i++)
    {
        for (int j = 0; j < this.radGridView1.ColumnCount; j++)
        {
            this.radGridView1.Rows[i].Cells[j].Value = r.Next(500).ToString();
        }
    }
}
 
//get values
for (int i = 0; i < this.radGridView1.RowCount; i++)
{
    for (int j = 0; j < this.radGridView1.ColumnCount; j++)
    {
        string myObj = this.radGridView1.Rows[i].Cells[j].Value.ToString();
    }
}

I hope this information is useful. Let me know if you need further assistance.

Regards,
Julian Benkov
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
0
hosein
Top achievements
Rank 1
answered on 16 Jun 2011, 05:21 PM
Hello
I have read the code from CustomObject Binding in Demo and changed it a little.
Now it Works fine for me
Thanks a lot
0
Petar
Top achievements
Rank 1
answered on 23 Sep 2011, 03:03 PM
I am interested in how you are able to bind to items in the second list. List<List<object>>
0
Julian Benkov
Telerik team
answered on 28 Sep 2011, 10:17 AM
Hi Petar,

Thank you for writing us.

For this type of binding you can use the sub-property binding functionality. For more information, please refer to our online documentation.

I hope this information is useful. Let me know if you need further assistance.

Kind regards,
Julian Benkov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
hosein
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
hosein
Top achievements
Rank 1
Petar
Top achievements
Rank 1
Share this question
or