locked
Bind ListItemCollection as a DataSource of a DataGridView RRS feed

  • Question

  • I am using SharePoint Server 2013. I am trying to show a list data in a DataGridView in a windows forms application(client application). I obtained the ListItemCollection object related to the specific list. How can I map that object to the datasource of the DataGridView?

    I can't find any specific way to obtain a DataTable object from the ListItemCollection object. Because the list I used to obtain data is selected by a drop down list. So there is no predetermined columns for a Datatable object. Thanks in advance. :)

    Saturday, November 9, 2013 12:05 PM

Answers

  • you can bind the gridview to a list or array but remember to set autogenerated columns to false and select only the columns you loaded while executing the query 

     dataGridView1.AutoGenerateColumns = false;
                context.Load(itemscoll,
                     items => items.Include(
                        item => item.Id,
                        item => item.DisplayName,
                        item => item.HasUniqueRoleAssignments));
                context.ExecuteQuery();
    
                dataGridView1.DataSource = itemscoll.ToList();


    Hope that helps|Amr Fouad|MCTS,MCPD sharePoint 2010


    • Edited by Amr FouadMVP Saturday, November 9, 2013 10:20 PM
    • Proposed as answer by Girish Goudar Sunday, November 10, 2013 7:38 AM
    • Marked as answer by Patrick_Liang Tuesday, November 19, 2013 8:58 AM
    Saturday, November 9, 2013 10:19 PM

All replies

    • Proposed as answer by Amr FouadMVP Monday, November 11, 2013 4:00 PM
    Saturday, November 9, 2013 1:02 PM
  • @Girish

    Unfortunately, ListItemCollection object in SharePoint Client Object Model doesn't have a GetDataTable() method. :( 

    Thanks for the help.cheers.

    Saturday, November 9, 2013 1:07 PM
  • you can bind the gridview to a list or array but remember to set autogenerated columns to false and select only the columns you loaded while executing the query 

     dataGridView1.AutoGenerateColumns = false;
                context.Load(itemscoll,
                     items => items.Include(
                        item => item.Id,
                        item => item.DisplayName,
                        item => item.HasUniqueRoleAssignments));
                context.ExecuteQuery();
    
                dataGridView1.DataSource = itemscoll.ToList();


    Hope that helps|Amr Fouad|MCTS,MCPD sharePoint 2010


    • Edited by Amr FouadMVP Saturday, November 9, 2013 10:20 PM
    • Proposed as answer by Girish Goudar Sunday, November 10, 2013 7:38 AM
    • Marked as answer by Patrick_Liang Tuesday, November 19, 2013 8:58 AM
    Saturday, November 9, 2013 10:19 PM