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 8197041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:39:30+00:00 2026-06-07T05:39:30+00:00

i bind linq result data to datagrid but nothing comes. here is my code

  • 0

i bind linq result data to datagrid but nothing comes. here is my code

        List<SearchResult> list = new List<SearchResult>() {
        new SearchResult(){ID=1,Title="Geo Prism 1995 GEO* - ABS #16213899"},
        new SearchResult(){ID=2,Title="Excavator JCB - ECU P/N: 728/35700"},
        new SearchResult(){ID=3,Title="Geo Prism GEO 1995 - ABS #16213899"},
        new SearchResult(){ID=4,Title="JCB Excavator JCB- ECU P/N: 728/35700"},
        new SearchResult(){ID=5,Title="Geo Prism GEO,GEO 1995 - ABS #16213899 GEO"},
        new SearchResult(){ID=6,Title="dog"},
        };

        var to_search = new[] { "Geo", "JCB" }.Select(x => x.ToLower()).ToArray();
        var result = from searchResult in list
                     let title = searchResult.Title.ToLower()
                     let key_string = to_search.FirstOrDefault(ts => title.Contains(ts))
                     orderby key_string == null ? -1 : title.Split(new[] { key_string }, StringSplitOptions.None).Length descending
                     group searchResult by key_string into Group
                     orderby Group.Count() descending
                     select Group;

        dataGridView2.DataSource = result;

when i run the above code datagrid showing nothing but i was expecting datagrid should show ID and Title

then i add some more line like

List<SearchResult> listFinal = new List<SearchResult>();
foreach (var group in result)
{
     foreach (var item in group)
     {
        listFinal.Add(new SearchResult() { ID = item.ID, Title = item.Title });
     }
 }
 dataGridView2.DataSource = listFinal;

now datagrid is showing data. so my question is that….is there any short cut way to convert result to list as a result i can bind list directly to datagrid with iterate in loop and create a new list and fill it up before binding. looking for guidance. thanks

  • 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-07T05:39:31+00:00Added an answer on June 7, 2026 at 5:39 am

    Yes, just call .SelectMany() and .ToList() on your LINQ query.

    dataGridView2.DataSource = result.SelectMany(e => e).ToList();
    

    or create your List with the appropriate constructor:

    dataGridView2.DataSource = new List(result.SelectMany(e => e));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I bind a list<> to a datagrid. Then, in the code behind, I change
I'm trying to bind a list of data to a data grid, but can't
I have an anonymous linq query that I bind to a datagrid, when I
I have a gridview that I bind with the result of a linq query
I'm trying to use LINQ to bind the data in my GridView. In my
I'm using LINQ to query data from database and then bind it to a
I am new with Linq and I would like to sort some data that
I'm trying to figure out how to bind a datagrid's itemsource to a List.
I bind the ItemsSource of a ComboBox to an ObservableCollection<MyClass> . In code I
I get an ArrayOfXelement for a result by a webservice. But now I wish

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.