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

  • SEARCH
  • Home
  • 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 6973683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:08:22+00:00 2026-05-27T17:08:22+00:00

I have a datatable bound to a datagridview. However, the ordering of columns is

  • 0

I have a datatable bound to a datagridview. However, the ordering of columns is messed up. I already made a column headers for each field put dataproperty name. I arranged it in the designer view. However, if i run the program column headers doesn’t follow my arrangement. =_=. Does anybody know how to solve this….

EDIT::
I’ve Tried this approach. Is it Okay?

void SortDataGridViewColumns(DataGridView dgv)
{
    var list = from DataGridViewColumn c in dgv.Columns
               orderby c.Index
               select c;

    int i = 0;
    foreach (DataGridViewColumn c in list)
    {
        c.DisplayIndex = i++;
    }
}

***I’ve got this here but I use Index instead of Headertext. CASE CLOSED! LOL

  • 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-05-27T17:08:23+00:00Added an answer on May 27, 2026 at 5:08 pm

    I think you wil need to change the column order in runtime.

    From MSDN:

    When you use a DataGridView to display data from a data source, the columns in the data source’s schema sometimes do not appear in the order you would like to display them. You can change the displayed order of the columns by using the DisplayIndex property of the DataGridViewColumn class.

    You can change the order of the columns like this:

    private void AdjustColumnOrder()
    {
        customersDataGridView.Columns["CustomerID"].Visible = false;
        customersDataGridView.Columns["ContactName"].DisplayIndex = 0;
        customersDataGridView.Columns["ContactTitle"].DisplayIndex = 1;
        customersDataGridView.Columns["City"].DisplayIndex = 2;
        customersDataGridView.Columns["Country"].DisplayIndex = 3;
        customersDataGridView.Columns["CompanyName"].DisplayIndex = 4;
    }
    

    http://msdn.microsoft.com/en-us/library/wkfe535h.aspx#Y0

    If you’re going t use it frequently, I recomend you to make use of extension methods to add sintactic sugar and make it easy to read and maintain.

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

Sidebar

Related Questions

I have a DataGridView that is bound to a DataTable, it has a column
I have a DataGridView bound to a DataTable that has 1+16 columns defined as
I have a datatable bound to my datagridview. One of the columns is a
I have a datagridview bound from a datatable. I have a calculated column linetotal
I have a DataTable which is bound to DataGridView . DataTable has several columns
I have a DataGridView which is bound to a DataTable that contains a column
I have a DataTable which is bound to datagridview (Winforms)... I use the following
I have a datatable bound to a winforms dataGridView via a BindingSourceControl. I want
I Have a Datagridview bound to a datatable wich hold data from a database
I have a datagridview which is initially bound to an empty datatable. Then the

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.