How to: Create a Custom Column Chooser

  • 2 minutes to read

This example shows how to create a custom standalone Column Chooser and display it in the same window as the GridControl.

<Window x:Class="DevExCustomColumnChooser.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
        xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        >
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="170"/>
        </Grid.ColumnDefinitions>

        <dxg:GridControl x:Name="grid" AutoGenerateColumns="AddNew">
            <dxg:GridControl.View>
                <dxg:TableView x:Name="tableView">
                    <dxg:TableView.ColumnMenuCustomizations>
                        <dxb:RemoveAction ElementName="{x:Static dxg:DefaultColumnMenuItemNames.ColumnChooser}"/>
                    </dxg:TableView.ColumnMenuCustomizations>
                </dxg:TableView>
            </dxg:GridControl.View>
        </dxg:GridControl>

        <dxg:ExtendedColumnChooserControl Grid.Column="1"
                                          Owner="{Binding ElementName=tableView}" 
                                          FlowDirection="{Binding Owner.FlowDirection, RelativeSource={RelativeSource Self}}"/>
    </Grid>
</Window>
using System.Collections.Generic;
using System.Windows;

namespace DevExCustomColumnChooser {
    public partial class MainWindow: Window {
        public MainWindow() {
            InitializeComponent();
            grid.ItemsSource = IssueList.GetData();
        }
    }

    public class IssueList {
        static public List<IssueDataObject> GetData() {
            var data = new List<IssueDataObject>
                {
                    new IssueDataObject()
                        {
                            IssueName = "Transaction History",
                            IssueType = "Bug",
                            IsPrivate = true
                        },
                    new IssueDataObject()
                        {
                            IssueName = "Ledger: Inconsistency",
                            IssueType = "Bug",
                            IsPrivate = false
                        },
                    new IssueDataObject()
                        {
                            IssueName = "Data Import",
                            IssueType = "Request",
                            IsPrivate = false
                        },
                    new IssueDataObject()
                        {
                            IssueName = "Data Archiving",
                            IssueType = "Request",
                            IsPrivate = true
                        }
                };
            return data;
        }
    }
    public class IssueDataObject {
        public string IssueName { get; set; }
        public string IssueType { get; set; }
        public bool IsPrivate { get; set; }
    }
}