This is a migrated thread and some comments may be shown as answers.

Hide Column / Column Chooser Events

2 Answers 222 Views
GridView
This is a migrated thread and some comments may be shown as answers.
erwin
Top achievements
Rank 1
Veteran
Iron
erwin asked on 01 Oct 2013, 05:42 PM
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 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 04 Oct 2013, 12:24 PM
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 >>
0
erwin
Top achievements
Rank 1
Veteran
Iron
answered on 07 Oct 2013, 10:55 AM

Thanks, Mark.

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

Regards
Erwin
Tags
GridView
Asked by
erwin
Top achievements
Rank 1
Veteran
Iron
Answers by
George
Telerik team
erwin
Top achievements
Rank 1
Veteran
Iron
Share this question
or