Hide Column / Column Chooser Events

3 posts, 0 answers
  1. erwin
    erwin avatar
    358 posts
    Member since:
    Dec 2006

    Posted 01 Oct 2013 Link to this post

    Hi!

    what's the best event to check if the user has interactively hidden a column or selected a column from the column chooser?

    Regards
    Erwin
  2. George
    Admin
    George avatar
    500 posts

    Posted 04 Oct 2013 Link to this post

    Hi Erwin,

    Thank you for contacting us.

    You can detect whether a user has hidden a column using the context menu by subscribing to the corresponding RadMenuItem. You can also subscribe to the DoubleClick event of the hidden columns in order to be notified when a user is unhiding a column from the ColumnChooser:
    this.grid.ContextMenuOpening += grid_ContextMenuOpening;
     
    private void SubscribeForItemsInColumnChooser()
    {
        foreach (var item in this.grid.ColumnChooser.ColumnChooserControl.ColumnChooserElement.ElementsHolder.Children)
        {
            ColumnChooserItem columnItem = item as ColumnChooserItem;
            if (columnItem != null)
            {
                columnItem.DoubleClick -=columnItem_DoubleClick;
                columnItem.DoubleClick +=columnItem_DoubleClick;
            }
        }
    }
      
    void columnItem_DoubleClick(object sender, EventArgs e)
    {
        RadMessageBox.Show("User showing column");
    }
      
    void grid_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
    {
        foreach (object item in e.ContextMenu.Items)
        {
            RadMenuItem menuItem = item as RadMenuItem;
            if (menuItem != null && menuItem.Text == "Hide Column")
            {
                menuItem.Click -= menuItem_Click;
                menuItem.Click += menuItem_Click;
            }
        }
    }
      
    void menuItem_Click(object sender, EventArgs e)
    {
        RadMessageBox.Show("User Hiding Column");
        this.SubscribeForItemsInColumnChooser();
    }

    You can also use the PropertyChanged event of the columns:
    foreach (GridViewColumn item in this.grid.Columns)
    {
        item.PropertyChanged += item_PropertyChanged;
    }
     
    void item_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        if (e.PropertyName == "IsVisible")
        {
        }
    }

    I hope this helps.
     
    Regards,
    George
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. erwin
    erwin avatar
    358 posts
    Member since:
    Dec 2006

    Posted 07 Oct 2013 Link to this post


    Thanks, Mark.

    I'ver implemented the Property Changed Event solution, works perfectly.

    Regards
    Erwin
Back to Top