Win Datagrid Hide Column

How can I hide a column in a windows datagrid - specifically a mobile datagrid - setting width to 0 is not the answer I am hoping for...
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

if you have a datagrid called datagrid, u just can get the right column by index and set his visible property to false like this:

dataGridView1.Columns[0].Visible = false;
it should say
"datagrid called dataGridView1" of course :)
tbaseflugAuthor Commented:
here is what I get:  'System.Windows.Forms.DataGrid' does not contain a definition for 'Columns'      
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

sorry, i was using DataGridView, one moment :)
"How to Hide a DataGrid Column Dynamically?" i hope you enjoy this article
Hmmm, that article applies to the web datagrid. Is that what you need tbaseflug? If not, then this is what i use in windows clients, i'm not sure about mobile clients. I work with the TableStyles collection property of the datagrid. This is the mechanism by which, in 1.1, you could alter the appearance of specific columns in a datagrid. You add only the columns to the TableStyle collection that you want to see.

Do you want a code example?

tbaseflugAuthor Commented:
Andy -

That is exactly what I am looking for.
Sorry, I'm not clear - do you need a code example? Or did you mean that that answered your question?
tbaseflugAuthor Commented:
Code example would be great - thanks!
tbaseflugAuthor Commented:
Here is what I am using now - The problem is that when it gets to the following line it throws this error:

line of error: grdOrders.TableStyles.Add(dgtsStyle);
error: Value does not fall within the expected range.

Here is the code that I am using now:
        public void AddCustomDataTableStyle(int Mode)
            DataGridTableStyle dgtsStyle;
            DataGridTextBoxColumn dgtsColumn;
            DataGridTextBoxColumn dgtsColumn1;
            DataGridTextBoxColumn dgtsColumn2;

            dgtsStyle = new DataGridTableStyle();
            dgtsStyle.MappingName = grdOrders.DataSource.ToString();

            if (Mode == 1 || Mode == 3)
                // Set Order Quantity
                dgtsColumn1 = new DataGridTextBoxColumn();
                dgtsColumn1.MappingName = "OrderQuantity";
                dgtsColumn1.HeaderText = "Ord";
                dgtsColumn1.Width = 26;

            if (Mode == 2 || Mode == 3)
                // Set Quantity On Hand
                dgtsColumn2 = new DataGridTextBoxColumn();
                dgtsColumn2.MappingName = "QuantityOnHand";
                dgtsColumn2.HeaderText = "QOH";
                dgtsColumn2.Width = 26;

            // Set Par Level
            dgtsColumn = new DataGridTextBoxColumn();
            dgtsColumn.MappingName = "ParLevel";
            dgtsColumn.HeaderText = "Par";
            dgtsColumn.Width = 26;

            // Set Item Description
            dgtsColumn = new DataGridTextBoxColumn();
            dgtsColumn.MappingName = "Description";
            dgtsColumn.HeaderText = "Description";
            dgtsColumn.Width = 160;

            // Set ItemID - set width to 0 to hide from display
            dgtsColumn = new DataGridTextBoxColumn(); ;
            dgtsColumn.MappingName = "ItemID";
            dgtsColumn.Width = 0;

            //if (TablesAlreadyAdded) return;

            //  Add the style to the DataGrid.

            // Set the TablesAlreadyAdded to prevent redundant execution
            //TablesAlreadyAdded = true;
            //return dgtsStyle;


Hi  100 % solution what you want in c#

Test code can be donload at this link

The only difference between your code and the code example I started writing for you last night is that I was using


i.e., clearing the table styles collection first.

Does that work?


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SystemExpert: your link is for web datagrids. tbaseflug needs windows datagrids - do you have any you would recommend for that?

I haven't looked at your code, but have you seen this?:
(How to: Delete or Hide Columns in the Windows Forms DataGrid Control)
Is it possible that one of your mappingname's is not corresponding to a column name in your datasource table?

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.