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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:08:41+00:00 2026-06-16T06:08:41+00:00

The code I would like to write would look like this: IEnumerable<SomeModel> items =

  • 0

The code I would like to write would look like this:

IEnumerable<SomeModel> items = GetTheItems();

dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = BuildTheDataSource(items);

And the data grid would show the sort glyphs on the headers and allow the user to sort by clicking them.

The most promising lead I’ve had so far was the SortableBindingList proposed by this answer, but that solution (and others) seem to work only for manually created columns.

Update

Well the egg is on my face now! The SortableBindingList does work, but I made a classic blunder:

void Bind(List<Model> items)
{
    this.items = new SortableBindingList<Model>(items);

    // oops! "items" is a List<T>... what I really wanted was
    // "this.items" which is a SortableBindingList<T>
    dataGridView1.DataSource = items;
}
  • 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-16T06:08:42+00:00Added an answer on June 16, 2026 at 6:08 am

    If i understand your question. The given example of SortableBindingList

    is thus:

            this.dataGridView1.AutoGenerateColumns = false;
    
            this.ColumnId.DataPropertyName = "Id";
            this.ColumnFirstName.DataPropertyName = "FirstName";
            this.ColumnLastName.DataPropertyName = "LastName";
            this.ColumnBirthday.DataPropertyName = "Birthday";
            this.ColumnScore.DataPropertyName = "Score";
    
            List<Person> list = new List<Person>();
            list.Add(new Person(1, "Tim", "4", new DateTime(1980, 4, 30), 100.1));
            list.Add(new Person(2, "Amy", "2", new DateTime(1983, 1, 1), 200.2));
            list.Add(new Person(3, "Sarah", "3", new DateTime(1984, 1, 24), 300.3));
            list.Add(new Person(4, "Mike", "1", new DateTime(1988, 3, 21), 400.4));
    
            SortableBindingList<Person> persons = new SortableBindingList<Person>(list);
    
            this.dataGridView1.DataSource = persons;
    

    so, from the List<Person> to SortableBindingList the column is created base in the Fields and Properties of the Person.

    what did you mean from your question?:

    but that solution (and others) seem to work only for manually created columns.

    Update

    Try this one

            dataGridView1.AutoGenerateColumns = true;
            IEnumerable<SomeModel> items = GetTheItems();
    
            SortableBindingList<SomeModel> items = new SortableBindingList<SomeModel>(items.ToList()); 
            dataGridView1.DataSource = items;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to write a code in Ruby that behaves like this C#
I would like to write some Objective-C code for distribution. What is the best
Can .NET (managed code) read and write to CouchDB? I would like to build
I'd like to write a function that would have some optional code to be
I would like to see how this example of existing code would be able
Code I'm writing an xml file with cElementTree like this: cElementTree.ElementTree(xml_tree]).write(xmlPath, encoding=ISO-8859-1, xml_declaration=True) actual
I am not familiar with C-like syntaxes and would like to write code to
I would like to compare two classes that look like this public class Order
Here is what I would like to write in my java code: private <A
I would like to write code in .hpp without separation to .h and .cpp

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.