Welcome to the Xceed Community | Help
Community Search  
More Search Options

Auto Hide/ Unhide of columns

Sort Posts: Previous Next
  •  09-22-2009, 9:28 AM Post no. 24074

    Auto Hide/ Unhide of columns

    Hi All,

    Can we implement auto hide/unhide based on the selection of the columns in the datagrid control.

    On selected columns, it should be hidden and later there should be provision to unhide the columns.

    Thanks in Advance.

    Regards,

    Siva

    Filed under:
  •  09-22-2009, 9:50 AM Post no. 24076 in reply to 24074

    Re: Auto Hide/ Unhide of columns

    The "column chooser" may do exactly what you need. It is available when you right-click in the column headers and allows you to show/hide columns. 
    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  09-22-2009, 10:02 AM Post no. 24077 in reply to 24076

    Re: Auto Hide/ Unhide of columns

    Hi Jenny,

    Actually i need to group some columns and hide/ unhide them.

    But column chooser will allow to choose one at a time.

    Please help me out.

    Thanks,

    Siva

    Filed under:
  •  10-13-2009, 6:47 AM Post no. 24443 in reply to 24077

    Re: Auto Hide/ Unhide of columns

    Any update on this feature?

     Please reply asap.

    Filed under:
  •  10-13-2009, 6:55 AM Post no. 24444 in reply to 24443

    Re: Auto Hide/ Unhide of columns

    What you are asking sounds quite application specific.What you could do is to implement your own context menu on the column header (don't use the column chooser) and hence hide/unhide the columns you want to group together. Then rather than your user giding one column and several disapper, the menu item can be worded to say what is being hidden.

    Just a thought.

  •  10-13-2009, 8:56 AM Post no. 24447 in reply to 24444

    Re: Auto Hide/ Unhide of columns

    Yes,

    It is possible but need to make Xceed DataGrid very Customized.

    We have implemented in our project having Column Choose in Grouping also.

    Kindly find the screen shot below:

     


    Nothing Is Impossible
  •  10-13-2009, 11:54 AM Post no. 24454 in reply to 24447

    Re: Auto Hide/ Unhide of columns

    Sample code will be helpful.

    Thanks in advance.

    Regards,

    Siva

    Filed under:
  •  10-14-2009, 2:57 AM Post no. 24474 in reply to 24454

    Re: Auto Hide/ Unhide of columns

    Here is the sample code from my column chooser replacement (it was done before column chooser was available so there maybe a better way now). It should give you an idea of how to develop your own logic for the hide/unhide but feel free to ask if it is not clear.

    In the XAML setup command bindings, the context menu and attach to the ColumnManagerCell

    <!-- CommandBindings for the Contextmenus in VPMPartList-->

    <xcdg:DataGridControl.CommandBindings>

     

    <CommandBinding Command="f:CLS_CustomCommands.HideGridColumn"

    CanExecute="CommandHideGridColumn_CanExecute"

    Executed="CommandHideGridColumn_Executed"/>

    <CommandBinding Command="f:CLS_CustomCommands.UnHideSpecificGridColumn"

    Executed="CommandUnHideSpecificGridColumn_Executed"/>

    </xcdg:DataGridControl.CommandBindings>

     

    <xcdg:DataGridControl.Resources>

    <ResourceDictionary>

    <ContextMenu x:Key="ColumnHeaderContextMenu" Opened="ColumnHeaderContextMenu_Opened">

    <MenuItem Command="f:CLS_CustomCommands.HideGridColumn"

    CommandTarget="{Binding RelativeSource={RelativeSource AncestorType={x:Type f:CLS_VPMPartListGrid}}}"

    CommandParameter="{Binding RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}, Path=PlacementTarget}"/>

    <MenuItem Header="UnHide Specific Column" Tag="mnuHiddenColumnsList"/>

    </ContextMenu>

    <!-- ColumnManagerCell Style definition -->

    <Style TargetType="{x:Type xcdg:ColumnManagerCell}">

    <Setter Property="ContextMenu" Value="{StaticResource ColumnHeaderContextMenu}"/>

    </Style>

     

    </ResourceDictionary>

     

    </xcdg:DataGridControl.Resources>

     

    <xcdg:DataGridControl.View>

    <xcdg:TableView ....

    AllowColumnChooser="False">

    </xcdg:TableView>

    </xcdg:DataGridControl.View>

     

    In the Code Behind Class...

    virtual protected void ColumnHeaderContextMenu_Opened(object sender, RoutedEventArgs e)

    {

    try

    {

    ContextMenu ctlContextMenu = sender as ContextMenu;

    //See if it exists already

    MenuItem mnuHiddenColumnsList = null;

    foreach (object contextMenuItem in ctlContextMenu.Items)

    {

    if (contextMenuItem is MenuItem)

    {

    MenuItem menuItem = contextMenuItem as MenuItem;

    if (menuItem.Tag != null && menuItem.Tag is string)

    {

    if ((string)menuItem.Tag == "mnuHiddenColumnsList")

    {

    mnuHiddenColumnsList = menuItem;

    break;

    }

    }

    }

    }

    //Now add the subMenu of the currently hidden columns

    if (mnuHiddenColumnsList != null)

    {

    mnuHiddenColumnsList.Items.Clear();

    CreateHiddenColumnMenuList(mnuHiddenColumnsList);

    mnuHiddenColumnsList.IsEnabled = (mnuHiddenColumnsList.Items.Count > 0);

    }

    }

    catch (Exception exception)

    {

    CLS_Global.GetGlobalSingleton().ExceptionHandler(exception);

    }

    }

    virtual protected void CreateHiddenColumnMenuList(MenuItem mnuHiddenColumnsList)

    {

    //In here you could either list all the columns that are hidden, or just the group names of the columns

    //that can be unhidden

    if (mnuHiddenColumnsList != null)

    {

    //Now add the columns

    List<ColumnBase> hiddenColumns = new List<ColumnBase>();

    foreach (ColumnBase thisColumn in Columns)

    {

    if (!thisColumn.Visible)

    {

    hiddenColumns.Add(thisColumn);

    }

    }

    //Order the columns by the FieldName

    List<ColumnBase> orderedHiddenColumns = hiddenColumns.OrderBy(c => c.Title).ToList();

    foreach (ColumnBase hiddenColumn in orderedHiddenColumns)

    {

    MenuItem menuNewColumn = new MenuItem();

    string sColumnName = hiddenColumn.Title.ToString();

    menuNewColumn.Header = sColumnName.Replace('\r', ' ');

    menuNewColumn.Command = CLS_CustomCommands.UnHideSpecificGridColumn;

    menuNewColumn.CommandParameter = hiddenColumn;

    menuNewColumn.CommandTarget = this;

    mnuHiddenColumnsList.Items.Add(menuNewColumn);

    }

    }

    }

     

     

    //The Hide event handler. Could be adapted to hide mroe than one

    protected void CommandHideGridColumn_Executed(object sender, ExecutedRoutedEventArgs e)

    {

    try

    {

    if (e.Parameter != null)

    {

    //Cannot hide the last column

    if (e.Parameter is Cell && Columns.Count(c => c.Visible) > 1)

    {

    ColumnBase thisColumn = ((Cell)e.Parameter).ParentColumn;

    thisColumn.Visible = false;

    }

    }

    }

    catch (Exception exception)

    {

    CLS_Global.GetGlobalSingleton().ExceptionHandler(exception);

    }

    }

    //The Unhide specific column - could be adapted to unhide more than one.

    protected void CommandUnHideSpecificGridColumn_Executed(object sender, ExecutedRoutedEventArgs e)

    {

    try

    {

    if (e.Parameter != null)

    {

    if (e.Parameter is ColumnBase)

    {

    ColumnBase thisColumn = e.Parameter as ColumnBase;

    thisColumn.Visible = true;

    if (thisColumn.Width < 5)

    {

    thisColumn.Width = 50;

    }

    }

    }

    }

    catch (Exception exception)

    {

    CLS_Global.GetGlobalSingleton().ExceptionHandler(exception);

    }

    }

     

  •  10-14-2009, 11:45 AM Post no. 24490 in reply to 24474

    Re: Auto Hide/ Unhide of columns

    Hi Derek,

    Thanks for the sample.

    Still this example is the same functionality of Column Chooser in the Xceed datagrid control.

    But my issue is am not able to group multiple columns to hide/ unhide. Now the columns also will be generated dynamically.

    I think you have understood the complexity.

     Thanks in advance.

    Regards,

    Siva

    Filed under:
  •  10-14-2009, 12:33 PM Post no. 24493 in reply to 24490

    Re: Auto Hide/ Unhide of columns

    I understand your requirements, but you are going to have to adapt the sample to your needs. I would expect that say you have 5 columns (A, B, C, D, E) and you want it so that if the user hides one of A, C or E that all 3 are hidden, and if the user selects B or D then both those are hidden.. etc.

    Therefore your app must know which columns are grouped together and the business logic probably gives them a name. Hence, in CommandHideGridColumn_Executed handler, if the column is A,C or E then loop through the grids column collection and hide A,C and E. Keep a collection/flag whatever, that this business logic collection is hidden.

    In CreateHiddenColumnMenuList, add a menu item for each of the business logic column groups that are hidden. If the user selects one (to Unhide it), then in CommandUnHideSpecificGridColumn_Executed you can identify which group is to be unhidden, and therefore loop through those columns to unhide them.

     

  •  10-14-2009, 12:40 PM Post no. 24494 in reply to 24493

    Re: Auto Hide/ Unhide of columns

    Thanks for the explanation derek.

    i am quite new to xceed datagrid. It would be great to provide a sample application and might help to implement the same.

    Anyway thanks in advance.

    Regards,

    Siva

     

    Filed under:
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.