locked
Specify which columns to display in datagridview RRS feed

  • Question

  • I have a query that pulls 4 columns and the WHERE condition is on a column I DO NOT want to display in a datagridview.

    Data is in a DataTable.

    In Designer I have 3 columns established (bound to the columns I want to display) but at run-time, the 4th column is inserted.

    How do I tell the datagridview not to insert the 4th column?



    • Edited by J Vallee Monday, January 20, 2020 2:53 PM
    • Moved by CoolDadTx Monday, January 20, 2020 4:42 PM Winforms related
    Monday, January 20, 2020 2:53 PM

Answers

  • Hello,

    Having columns defined in the DataGridView via the designer and have set DataPropertyName you then need to use

    dataGridView1.AutoGenerateColumns = false;
    This means no other columns in the DataGridView will display from the DataTable columns.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Proposed as answer by CoolDadTx Monday, January 20, 2020 4:42 PM
    • Marked as answer by J Vallee Monday, January 20, 2020 7:08 PM
    Monday, January 20, 2020 3:05 PM

All replies

  • Hello,

    Having columns defined in the DataGridView via the designer and have set DataPropertyName you then need to use

    dataGridView1.AutoGenerateColumns = false;
    This means no other columns in the DataGridView will display from the DataTable columns.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Proposed as answer by CoolDadTx Monday, January 20, 2020 4:42 PM
    • Marked as answer by J Vallee Monday, January 20, 2020 7:08 PM
    Monday, January 20, 2020 3:05 PM
  • Is this WinForms? Programmatically, you can set the DataGridViewColumn.Visible property to false

    How to: Hide Columns in the Windows Forms DataGridView Control


    william xifaras

    Monday, January 20, 2020 3:07 PM
  • Thank you!
    Monday, January 20, 2020 7:09 PM