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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:25:36+00:00 2026-06-13T07:25:36+00:00

I’m working with a DataGridView, and ran into a problem where the columns are

  • 0

I’m working with a DataGridView, and ran into a problem where the columns are sometimes not displayed in the correct order according to the DisplayIndex. I found a mention of the same problem on a different site, http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/35c1ed09-f4a4-4b3d-bd46-35a11cb8a9bc .

The problem seems to be when a column doesn’t show up on the initial display of the grid, due to being off to the right and requiring scrolling to see it. When the columns are few enough that all of them will be seen without scrolling, then the order is correct. If a column is added so that one of the columns will require scrolling to see it, then the column that is to the right will not be the last column according to the DisplayIndex, it will be a column that was supposed to be shown earlier.

While I could try and change the logic in my window to work similarly to the suggestion in the link above, I don’t like that the base problem is just glossed over and a work-around is required. Does anyone else have any suggestions as to how to address this problem in a way that addresses the problem itself instead of a work-around?

Here’s a code snippet of how I’m currently doing the ordering:

// Fill the data grid view with data from the database.
dataGridView1.DataSource = null;
DataTable dt = // Logic to get data from DB here
dataGridView1.DataSource = dt;

// Get the column display data.  This can change per user.
DataTable columnDisplay = // Logic to get data from DB here

bool foundMatch;

foreach (DataGridViewColumn column in dataGridView1.Columns)
{
    foundMatch = false;
    foreach (DataRow row in columnDisplay.Rows)
    {
        if (row["column_name"].ToString().Equals(column.Name, StringComparison.CurrentCultureIgnoreCase))
        {
            foundMatch = true;
            if (row["show_in_window"].ToString().Equals("y"))
            {
                // Set the column placement and display name.
                dataGridView1.Columns[column.Name].DisplayIndex = Convert.ToInt32(row["column_sequence"].ToString());
                dataGridView1.Columns[column.Name].HeaderText = row["display_name"].ToString();
                dataGridView1.Columns[column.Name].Width = 105;
            }
            else
            {
                // Hide the column.
                dataGridView1.Columns[column.Name].Visible = false;
            }
            break;
        }
    }

    // If the column is not in the display table, then it should not be displayed at all.
    if (!foundMatch)
        column.Visible = false;
}
  • 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-13T07:25:37+00:00Added an answer on June 13, 2026 at 7:25 am

    Alright, since no one has responded, I’ll give an update — I did not take the time to resolve this issue. It’s deemed a low enough priority that I may not get to it for months, if at all.

    One interesting piece of information that I found since the original post is that when modifying the display index number for a column, the rest of the columns are automatically changed to account for it. That was not obvious to me when I read the msdn documentation, so maybe it will be helpful for anyone else stumbling across this.

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

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I need a function that will clean a strings' special characters. I do NOT

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.