Get visible columns in displayed order

5 posts, 2 answers
  1. Chris Kirkman
    Chris Kirkman avatar
    91 posts
    Member since:
    Jul 2012

    Posted 08 Jan Link to this post

    I need to be able to programmatically get a list of the column headers that are currently being displayed in the grid.  I.e. my grid has 8 columns; however, the user may have changed the order and hidden some of the remaining columns (via the column chooser). 

    How do I ask the grid to give me the columns currently displayed and in left to right order?

  2. Answer
    Dess
    Admin
    Dess avatar
    2585 posts

    Posted 09 Jan Link to this post

    Hello, Chris,   

    Thank you for writing.  

    You can iterate the RadGridView.Columns collections and check whether the column is visible or not by the GridViewColumn.IsVisible property. Here is a sample code snippet:
    private void radButton1_Click(object sender, EventArgs e)
    {
        foreach (GridViewColumn col in this.radGridView1.Columns)
        {
            if (col.IsVisible)
            {
                Console.WriteLine(col.Name);
            }
        }
    }

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Chris Kirkman
    Chris Kirkman avatar
    91 posts
    Member since:
    Jul 2012

    Posted 09 Jan in reply to Dess Link to this post

    Dess, as usual you came through for me.  Thanks, that solved my problem. 

    How would I exclude command columns in my loop?  I've tried col.RadObjectType != typeof(GridViewCommandColumn) but the compiler says I can't do this.

  4. Answer
    Dess
    Admin
    Dess avatar
    2585 posts

    Posted 09 Jan Link to this post

    Hello, Chris,  

    Thank you for writing back. 

    I am glad that the provided code snippet was useful for your case. In order to exclude GridViewCommandColumns, you can refer to the following code snippet: 
    foreach (GridViewColumn col in this.radGridView1.Columns)
    {
        if (col.IsVisible && !(col is GridViewCommandColumn))
        {
            Console.WriteLine(col.Name);
        }
    }

    I hope this information helps. If you have any additional questions, please let me know. 

     Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Chris Kirkman
    Chris Kirkman avatar
    91 posts
    Member since:
    Jul 2012

    Posted 09 Jan in reply to Dess Link to this post

    that is perfect!  thanks.
Back to Top