How to bind nested generic list to radGridView?

5 posts, 0 answers
  1. hosein
    hosein avatar
    42 posts
    Member since:
    Oct 2010

    Posted 11 Jun 2011 Link to this post

    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

  2. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 15 Jun 2011 Link to this post

    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.
  3. hosein
    hosein avatar
    42 posts
    Member since:
    Oct 2010

    Posted 16 Jun 2011 Link to this post

    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
  4. Petar
    Petar avatar
    1 posts
    Member since:
    Nov 2010

    Posted 23 Sep 2011 Link to this post

    I am interested in how you are able to bind to items in the second list. List<List<object>>
  5. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 28 Sep 2011 Link to this post

    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 >>

Back to Top