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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:49:19+00:00 2026-06-05T00:49:19+00:00

I have a DGV bound to a binding source generation code here. // dgvDocumentList

  • 0

I have a DGV bound to a binding source generation code here.

            // dgvDocumentList
        // 
        this.dgvDocumentList.AllowUserToAddRows = false;
        this.dgvDocumentList.AllowUserToDeleteRows = false;
        this.dgvDocumentList.AutoGenerateColumns = false;
        this.dgvDocumentList.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
        this.dgvDocumentList.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
        this.dMTitleDataGridViewTextBoxColumn,
        this.urlCol,
        this.idCol});
        this.dgvDocumentList.DataSource = this.docListFetchBindingSource;
        this.dgvDocumentList.Dock = System.Windows.Forms.DockStyle.Fill;
        this.dgvDocumentList.Location = new System.Drawing.Point(3, 3);
        this.dgvDocumentList.MultiSelect = false;
        this.dgvDocumentList.Name = "dgvDocumentList";
        this.dgvDocumentList.ReadOnly = true;
        this.dgvDocumentList.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
        this.dgvDocumentList.Size = new System.Drawing.Size(336, 493);
        this.dgvDocumentList.TabIndex = 0;
        this.dgvDocumentList.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvDocumentList_CellContentDoubleClick);
        this.dgvDocumentList.SelectionChanged += new System.EventHandler(this.dgvDocumentList_SelectionChanged);

The Column code is here.

  // dCBModLinkDataGridViewTextBoxColumn
        // 
        this.dCBModLinkDataGridViewTextBoxColumn.DataPropertyName = "DCBModLink";
        this.dCBModLinkDataGridViewTextBoxColumn.HeaderText = "DCBModLink";
        this.dCBModLinkDataGridViewTextBoxColumn.Name = "dCBModLinkDataGridViewTextBoxColumn";
        this.dCBModLinkDataGridViewTextBoxColumn.ReadOnly = true;
        this.dCBModLinkDataGridViewTextBoxColumn.Visible = false;
        // 
        // dCBIDDataGridViewTextBoxColumn
        // 
        this.dCBIDDataGridViewTextBoxColumn.DataPropertyName = "DCBID";
        this.dCBIDDataGridViewTextBoxColumn.HeaderText = "DCBID";
        this.dCBIDDataGridViewTextBoxColumn.Name = "dCBIDDataGridViewTextBoxColumn";
        this.dCBIDDataGridViewTextBoxColumn.ReadOnly = true;
        this.dCBIDDataGridViewTextBoxColumn.Visible = false;
        // 
        // eQModModelNumberDataGridViewTextBoxColumn
        // 
        this.eQModModelNumberDataGridViewTextBoxColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
        this.eQModModelNumberDataGridViewTextBoxColumn.DataPropertyName = "EQModModelNumber";
        this.eQModModelNumberDataGridViewTextBoxColumn.HeaderText = "Model Number";
        this.eQModModelNumberDataGridViewTextBoxColumn.Name = "eQModModelNumberDataGridViewTextBoxCol

As you can see, the column definition for dcbModLinkDataGridViewTextBoxColumn says visble = false;
It also says this in the properties table. It still is visible in the application when run.

If I modify the postitions of the columns in the list I get the following results. No changed other than the order they appear on the columns list.

DCBID(Visible)–DCBModLink(Invisible)–EQModModelNumber(Visible)

DCBModLink(Visble)–DCBID(InVisible)–EQModModelNumber(Visible)

EQModModelNumber(Visible)–EQModModelNumber(Invisible)–DCBID(Invisible)

I have masked the symptom of this issue by leaving the column that I want in the first slot but I dont know why this particular DGV is behaving this way. There is another DGV on the same form that works fine no matter what position the columns are in.

I looked here: First Column Not Hiding in datagridview, and here datagridview id column will not hide But they just moved the problematice columns to the right like I did.

So. My questions are.

  1. Are there other setting that I am not aware of that can override the visibility pararameter?

  2. Has anyone else seen this and how did they stop it?

  • 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-05T00:49:21+00:00Added an answer on June 5, 2026 at 12:49 am

    i use an extension method for this which is my own.. and works very well..also this method sets the dgv client height and width programmatically.. with this ext method just

    1-)add dgv to your form

    2-)create lists of columns and header texts as what you want to show the user

    3-) call the method as yourDGV.showTheGivenColumns(your params, yourparams, yourparams)

    P.S. : i changed the names to english and add summary in english..here is the code..

    /// <summary>
      /// when this method called, it sets visible = false the columns where not in List of column names
      /// The column names List count and header List count must be the same number
      /// </summary>
      /// <param name="dgvName">DGV which calls this ext method</param>
      /// <param name="Method">the data source load method of the DGV which calls this ext method</param>
      /// <param name="ColumnName">The columnNames List which contains the columns will show.. columnName List's type is List<string></param>
      /// <param name="Header">The list where you can set the dgv's headers as you prefer..it's type is also List<string></param>
      /// <returns></returns>
      public static DataGridView showTheGivenColumns(this DataGridView dgvName, object dataSourceLoadMethod, List<string> columnNameList, List<string> headerList)
                {
                    dgvName.DataSource = null;
                    dgvName.Columns.Clear();
                    dgvName.DataSource = dataSourceLoadMethod;
                    int j = columnNameList.Count;
                    int m = 0;
                    int s = headerList.Count;
    
                    if (j == s)
                    {
    
                        foreach (DataGridViewColumn d in dgvName.Columns)
                        {
                            for (int i = 0; i < j; i++)
                            {
                                if (d.Name == columnNameList[i])
                                {
                                    d.HeaderText = headerList[i];
                                    d.Visible = true;
                                    d.Width = d.GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, false);
    
                                    m += d.Width;
                                    break;
                                }
                                else
                                {
                                    d.Visible = false;
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Count of Header and ColumnName Lists are not equal..Please Check.");
                    }
    

    ///after this line if your dgv has vertical and/or horizontal scroll, method will check and set the size with this option

    bool vscroll = (dgvName.DisplayedRowCount(false) < dgvName.Rows.Count);
                    bool hscroll = (dgvName.DisplayedColumnCount(false) < columnNameList.Count);
                    if (vscroll == true)
                    {
                        int vScrollWidth = (dgvName.Controls.OfType<VScrollBar>().First()).Width;
                        dgvName.Width = m + (vScrollWidth + 5);
                    }
                    if ( vscroll == false)
                    {
                        dgvName.Width = m + 5;
                    }
                    if (hscroll == true)
                    {
                        int hscrollWidth = (dgvName.Controls.OfType<HScrollBar>().First()).Height;
                        dgvName.Height = ((dgvName.RowTemplate.Height * dgvName.RowCount) + dgvName.ColumnHeadersHeight) + hscrollWidth;
    
                    }
                    if (hscroll == false)
                    {
                        dgvName.Height = ((dgvName.RowTemplate.Height * dgvName.RowCount) + dgvName.ColumnHeadersHeight) + 2;
                    }
    
                    dgvName.ClearSelection();
                    dgvName.ReadOnly = true;
                    return dgvName;
                 }
    

    YOU MAY WANT TO KNOW THESE :

    1-) in your form if your dgv’s size seems bigger than total columns then please set

    d.GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, false);
    

    method’s .AllCells option to your form’s needs.. if you set the false to true then your dgv will show the columns which flagged as half-showed..so we never need to change this 😉

    2-) in checking the needs of scrollbar code part, the numbers which added to width or height are depends to screen resolution..the numbers which i add is not the best but as much optimized for 1024*768, 1280*800 and 1366*968 resolution..You may need to change these added numbers..

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

Sidebar

Related Questions

Here's what I'm doing: I have (2) DataGridView controls DGV #1 is bound to
I have problem with adding image to DGV cell after data binding. this is
I have a DGV with columns code and name. Depends of lenght of a
have a php code like this,going to convert it in to C#. function isValid($n){
This a data binding question in C#. I have a simple Person class: public
I have a DGV I am binding to a list of objects. I set
I have a bound DGV that took a bit of work to get its
In my form3 i have this code Private Sub Form3_Load(ByVal sender As System.Object, ByVal
I have the DGV bound to data and all the other controls properly. What
I have a problem with data binding my user control into a DGV. When

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.