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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:56:39+00:00 2026-06-08T04:56:39+00:00

I have a grid that needs to hide certain columns right after its data-bound.

  • 0

I have a grid that needs to hide certain columns right after its data-bound. Here’s my code so far:

private IEnumerable<DataGridColumn> GetDataGridColumns(DataGrid grid)
{
    var itemsSource = grid.ItemsSource as IEnumerable;

    if (null == itemsSource) yield return null;

    foreach (var item in itemsSource)
    {
        var column = grid.ItemContainerGenerator.ContainerFromItem(item) as DataGridColumn;
        if (null != column) yield return column;
    }
}

private void LoadData()
{
    GridMain.ItemsSource = (new VTAEEntities()).OrganizationInterfaces.ToList();

    foreach (DataGridColumn Column in GetDataGridColumns(GridMain))
    {
        // Hiding columns
        if (Column.Header as String != null) {
            String tempHeader = Column.Header as String;

            String[] unrequiredColumns = new String[] { 
                "Instances",
                "Interfaces",
                "Organizations",
                "RegisteredCallerOnly"
            };

            if (unrequiredColumns.Contains(tempHeader)) {
                Column.Visibility = System.Windows.Visibility.Hidden;
            }
        }

        // Read-only columns
        if (Column.Header as String != null)
        {
            String tempHeader = Column.Header as String;

            String[] unrequiredColumns = new String[] { 
                "InstanceId",
                "InterfaceId",
                "OrganizationId"
            };

            if (unrequiredColumns.Contains(tempHeader))
            {
                Column.IsReadOnly = true;
            }
        }
    }
}

All the unwanted columns + the columns I want to be read only are all there. Upon debugging, I realize that the GridMain.Columns is always 0 count. How do I iterate through the columns in an ItemSource?

  • 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-08T04:56:41+00:00Added an answer on June 8, 2026 at 4:56 am

    If you want to hide column than you can make use of

    AutoGeneratingColumn
    

    event of wpf grid that will might work for you to hide column.

    private void DataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
    {
          DataGridBoundColumn col = e.Column as DataGridBoundColumn;
         //set visiblity by doing the code you wnat ..i.logic to hide column
          if (col.Header.ToString().ToLower() == "id") 
            { 
                col.Visibility = System.Windows.Visibility.Hidden;
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Telerik Grid which has a footer that needs to display column
I have a grid that has multiple rows. I want to hide/show one of
I have a grid view that has two simple columns, a report number and
I have the following hyperlink grid-view column that needs to be sorted numerically by
I have a DevExpress grid that needs to be refreshed every time the value
I have a Silverlight application that needs to scroll some data (like stock information)
I have a textBox that needs to be transformed into a DatePicker under certain
I need to have a grid on one of my webpages that will be
I have a grid that is dynamically generated based on search criteria. I render
Let's say I have some grid that looks like this _ _ _ _

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.