Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7776595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:55:28+00:00 2026-06-01T17:55:28+00:00

I have some List for storage data List<List<string>> data = new List<List<string>>(); How to

  • 0

I have some List for storage data

List<List<string>> data = new List<List<string>>();

How to correctly assign it to dataGridView.DataSource ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:55:29+00:00Added an answer on June 1, 2026 at 5:55 pm

    The problem here is (obviously) the DataGridView DataSource property doesn’t know how to display a List<List<string>>. One approach is to combine your Lists into one object which the DataGridView can bind to. Here are a couple ways to do this:

    To a DataTable:

    To convert your List<List<string>> to a DataTable, I borrowed the code found here and created this extension method:

    static class ListExtensions { 
        public static DataTable ToDataTable(this List<List<string>> list) { 
            DataTable tmp = new DataTable();
            tmp.Columns.Add("MyData");
            // Iterate through all List<string> elements and add each string value to a new DataTable Row.        
            list.ForEach(lst => lst.ForEach(s => tmp.Rows.Add(new object[] {s})));
    
            return tmp; 
        } 
    }
    

    Here’s now you can use this extension method to get a DataTable from your List<List<string>> which you can bind to your DataGridView:

    dataGridView.DataSource = data.ToDataTable();
    

    To an anonymous type List:

    Here is the code for doing this:

    dataGridView.DataSource = data.SelectMany(lst => lst)
                                  .Select(s => new { Value = s }).ToList();
    

    We need the anonymous type because a DataGridView won’t be able to display the string values in List property without a little help, as described here.


    There are of course disadvantages to either these approaches but I do believe something along these lines is your best option.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say you have a simple class with some storage data structure (list, vector, queue,
I have some C structures related to a 'list' data structure. They look like
I have some financial data gathered at a List[(Int, Double)], like this: val snp
I have some std::list<char> list_type Now I have to supply contents of the list
If I have some R list mylist , you can append an item obj
I have some LINQ code that generates a list of strings, like this: var
I have some code that inserts a list item into a list... I then
We have some code which sorts a list of addresses based on the distance
I have some code to display a long list of languages inside Rails form
you have some info on an item and you got a list of comment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.