Hide or show columns

6 posts, 1 answers
  1. Hugo Aristizabal
    Hugo Aristizabal avatar
    22 posts
    Member since:
    Jan 2010

    Posted 11 May 2010 Link to this post

    Hi. I'm developing a form on which the user can select one of many reports to show, and I have two questions on the GridView:

    1. Do you always have to specify a Columns collection? I mean, because I can have many different reports for the same GridView, I want to be able to show them all without having to specify the columns individually.
    2. How do you programatically hide or show a column at a specific index or with a specific header? My user wants to be able to hide some columns before exporting the report results, so I'm planning on showing him a CheckBox list with the columns, so he can choose which ones to show/hide.

    Thanks a lot.
  2. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 12 May 2010 Link to this post

    Hi Hugo Aristizabal,

    There is no need to define columns collection if you do not need to. You can use the property of RadGridView AutoGenerateColumns and set it to "true". Thus the columns will be based on the properties of the data item it is bound to.  A column is created for every public property of simple type (integer, string, date, enum and boolean).
    As for your second question, you can hide or show programatically a column with a specific index. If you want to use Check Boxes, you may add  the following lines when each one is checked:

    this.RadGridView1.Columns[1].IsVisible = false;

    Where the index in Columns[ ] specifies the column you want to hide or if it is set to "true" - to show.

    I hope that helps.

    Best wishes,
    Maya
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Tarik
    Tarik avatar
    4 posts
    Member since:
    Jul 2010

    Posted 10 Sep 2010 Link to this post

    Hello,

    What if I want to hide the nest grids columns, my datasource has tables linked and I just dump them in the grid (don't know what will be in them at design time) Please let me know how I can do that in the code behind
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 13 Sep 2010 Link to this post

    Hi,

     You can use DataLoading/AutoGeneratingColumn events to assess auto-generated child grid columns or you can define directly desired child grid columns using HierarchyChildTemplate. You can check this demo for more info.

    Best wishes,
    Vlad
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Tarik
    Tarik avatar
    4 posts
    Member since:
    Jul 2010

    Posted 13 Sep 2010 Link to this post

    Thanks for the reply, the AutoGeneratingColumn event doesn't do the job. My parent table has 3 columns, so the event gets fired 3 times. I am able to capture the columns from the event handler via the code below but I'm interested in capturing the children grids. Thank you for sending the example but I'm not sure it's what I need as I don't know what the child tables will look like (sometimes they might have 10 columns others 15). Could you please show me a code example of deleting child columns?

    Thank you

    //this works because it can see the parent table's columns

     

     

    if (e.Column.Header.ToString().ToUpper() == "BLOCK_ID")

     

    {

    e.Column.IsVisible =

     

    false;

     

    }

  7. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 13 Sep 2010 Link to this post

    Hi,

     You can subscribe to AutoGeneratingColumn for child tables using DataLoading:

    var grid = (GridViewDataControl)sender;
    if(grid.ParentRow != null)
    {
    grid.AutoGeneratingColumn += ...
    }

    Regards,
    Vlad
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready