v
Not logged inv
SearchAsk a QuestionReport an IssueMake a SuggestionMy Questions and Issues
KB Article
Find By ID

How to add a quick columns customization drop-down menu to a GridView

Article Details

K18345
10/25/2011
.NET (WinForms)
XtraGrid Suite

How to add a custom drop-down menu to a GridView, which will allow to show/hide columns and change columns order?

Solution

For this purpose, you should create a GridView descendant, as shown in the How to create a GridView descendant that will allow users to customize columns order and visibility in a new drop-down menu example.

First of all, you should customize your GridView descendant for displaying a new column customization button on the column button and invoking the new ShowColumnCustomizationMenu method when a user clicks this button. For this purpose, the GridViewInfo, GridPainter and GridHandler descendants should be created. Moreover, you can add the GridView.OptionsCustomization.AllowQuickCustomizations and GridView.OptionsCustomization.QuickCustomizationIcon properties to your grid view descendant. This task can be accomplished by creating the ViewBaseOptions and GridOptionsCustomization classes descendants. Currently, the GridColumn class does not have the capability to prevent column hiding. A new GridColumn.OptionsColumn.AllowQuickHide property should be created for providing this capability. This task can be accomplished by creating the GridColumn, GridColumnCollection and OptionsColumn classes descendants.

Now, your GridView descendant is ready, and you need to create a drop-down menu for columns customization. For this purpose, create a CheckedListBoxControl descendant. Override the OnMouseMove, OnMouseUp and OnMouseDown methods to implement dragging functionality. The CheckedListBoxViewInfo, CheckedItemInfo and PainterCheckedListBox descendants should be created for making the dragging process visible.

After that, create a PopupContainerEdit descendant, which will implement the following functionality:
1) Display the GridView.OptionsCustomization.QuickCustomizationIcon when the editor is active. The inactive editor should be hidden.
2) Get information about the columns from the GridView.
3) Populate the CheckedListBoxControl with items, created according to this information.
4) Read the customization result and provide it for the GridView.
5) Show your custom CheckedListBoxControl with the PopupContainerEdit.PopupForm.

For the first task, the GridView.CreateHideEdit, GridView.LocateHideEdit, GridView.ShowColumnCustomizationMenu methods should be created. For the second task, the ColumnProperties, ColumnPropertiesCollection classes and the GridView.PopulateHideEdit methods should be created. For the third and fourth tasks, the PopupContainerForm.PopulateListBox, PopupContainerForm.GetCollumns and GridView.AcceptQuickHide methods should be created. For the fifth task, the PopupContainerEdit.CreatePopupControl and PopupContainerForm.CreateChekedListBox methods should be created.

Finally, override the GridView.IsFocusedView property it should return the True value when the drop-down menu has focus.

See Also:
How to create a GridView descendant class and register it for design-time use
How to inherit grid columns and use them in the XtraGrid

Example: How to create a GridView descendant that will allow users to customize columns order and visibility in a new drop-down menu

Log in to Track Changes
Download Example Example Runner
E2015
Microsoft Visual Studio 2005, Microsoft Visual Studio 2008, Microsoft Visual Studio 2010
v2009 vol 2.9 - v2011 vol 2.8
v
XtraGrid Suite
XtraGrid
4/6/2010

This example shows how to create a GridView descendant that will allow users to customize columns order an visibility in a new drop-down menu. This drop-down menu allows hiding columns by the check box checking or un checking, and change columns order simply by items dragging.

The drop-down menu can be invoked by clicking the quick customization button, which is placed on the column button.
This menu can be disabled by specifying the GridView.OptionsCustomization.AllowQuickCustomizations property. You can use the GridView.OptionsCustomization.QuickCustomizationIcon property to specify an image, displayed on the quick customization button.
Keep in mind that, not all the columns can be moved or hidden in compliance with GridView and GridColumn options.
The column moving capability can be disabled by setting the GridView.OptionsCustomization.AllowColumnMoving and GridColumn.OptionsColumn.AllowMove properties to False. A column cannot be hidden if the GridView.OptionsCustomization.AllowQuickHideColumns or GridColumn.OptionsColumn.AllowQuickHide property has the False value. The GridColumn.OptionsColumn.AllowQuickHide property is a new property, implemented in this descendant only. If a column's GridColumn.OptionsColumn.ShowInCustomizationForm property has the False value, this column will be displayed in the column customization drop-down menu only when it is visible.

See Also:
How to add a quick columns customization drop-down menu to a GridView

Log in to Track Changes
Download Example Example Runner

Do you have any comments? We are eager to hear them!

0 people have rated this page
Post Your Vote (Login Required)
v
v
Search
Searching Tips