첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainWindow.xaml

<Window x:Class="TestProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
    Width="800"
    Height="600"
    Title="마스터 행 확장하기/축소하기"
    FontFamily="나눔고딕코딩"
    FontSize="16"
    Loaded="Window_Loaded">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"   />
            <ColumnDefinition Width="150" />
        </Grid.ColumnDefinitions>
        <dxg:GridControl x:Name="gridControl"
            Grid.Column="0"
            AutoGenerateColumns="AddNew">
            <dxg:GridControl.View>
                <dxg:TableView
                    x:Name="tableView"
                    ShowGroupPanel="False"
                    PreviewKeyDown="tableView_KeyDown" />
            </dxg:GridControl.View>
            <dxg:GridControl.DetailDescriptor>
                <dxg:DataControlDetailDescriptor ItemsSourcePath="OrderList">
                    <dxg:DataControlDetailDescriptor.DataControl>
                        <dxg:GridControl AutoGenerateColumns="AddNew">
                            <dxg:GridControl.View>
                                <dxg:TableView
                                    ShowGroupPanel="False" />
                            </dxg:GridControl.View>
                        </dxg:GridControl>
                    </dxg:DataControlDetailDescriptor.DataControl>
                </dxg:DataControlDetailDescriptor>
            </dxg:GridControl.DetailDescriptor>
        </dxg:GridControl>
        <StackPanel
            Grid.Column="1"
            Margin="10"
            Orientation="Vertical">
            <Button x:Name="expandAllButton"
                Click="expandAllButton_Click"
                Margin="0 10 0 0"
                Content="Expand All" />
            <Button x:Name="collapseAllButThisButton"
                Margin="0 10 0 0"
                Content="Collapse All But This"
                Click="collapseAllButThisButton_Click" />
            <TextBlock
                Margin="0 30 0 0"
                TextWrapping="Wrap">
                Press <Bold>CTRL+*</Bold> to toggle focused master row's expanded state
            </TextBlock>
        </StackPanel>
    </Grid>
</Window>

 

728x90

 

▶ MainWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;

using DevExpress.Xpf.Grid;

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public partial class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 직원 리스트
        /// </summary>
        private List<Employee> employeeList;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 직원 리스트 - EmployeeList

        /// <summary>
        /// 직원 리스트
        /// </summary>
        private List<Employee> EmployeeList
        {
            get
            {
                if(this.employeeList == null)
                {
                    CreateEmployeeList();
                }

                return this.employeeList;
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region 윈도우 로드시 처리하기 - Window_Loaded(sender, e)

        /// <summary>
        /// 윈도우 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.gridControl.ItemsSource = EmployeeList;
        }

        #endregion
        #region 테이블 뷰 키 DOWN시 처리하기 - tableView_KeyDown(sender, e)

        /// <summary>
        /// 테이블 뷰 키 DOWN시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void tableView_KeyDown(object sender, KeyEventArgs e)
        {
            TableView tableView = sender as TableView;

            if(!tableView.IsFocusedView || tableView.FocusedRowHandle < 0)
            {
                return;
            }

            if(e.Key == Key.Multiply && ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control))
            {
                bool isMasterRowExpanded = !tableView.Grid.IsMasterRowExpanded(tableView.FocusedRowHandle);

                tableView.Grid.SetMasterRowExpanded(tableView.FocusedRowHandle, isMasterRowExpanded);

                e.Handled = true;
            }
        }

        #endregion
        #region Expand All 버튼 클릭시 처리하기 - expandAllButton_Click(sender, e)

        /// <summary>
        /// Expand All 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void expandAllButton_Click(object sender, RoutedEventArgs e)
        {
            int employeeListCount = EmployeeList.Count;

            for(int rowHandle = 0; rowHandle < employeeListCount; rowHandle++)
            {
                this.gridControl.ExpandMasterRow(rowHandle);
            }
        }

        #endregion
        #region Collapse All But This 버튼 클릭시 처리하기 - collapseAllButThisButton_Click(sender, e)

        /// <summary>
        /// Collapse All But This 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void collapseAllButThisButton_Click(object sender, RoutedEventArgs e)
        {
            int employeeListCount = EmployeeList.Count;

            if(this.tableView.FocusedRowHandle >= 0) 
            {
                this.gridControl.ExpandMasterRow(this.tableView.FocusedRowHandle);
            }

            for(int rowHandle = 0; rowHandle < employeeListCount; rowHandle++)
            {
                if(rowHandle != this.tableView.FocusedRowHandle)
                {
                    this.gridControl.CollapseMasterRow(rowHandle);
                }
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region 직원 리스트 생성하기 - CreateEmployeeList()

        /// <summary>
        /// 직원 리스트 생성하기
        /// </summary>
        private void CreateEmployeeList()
        {
            this.employeeList = new List<Employee>();

            this.employeeList.Add
            (
                new Employee
                (
                    "Bruce",
                    "Cambell",
                    "Sales Manager",
                    "Education includes a BA in psychology from Colorado State University in 1970. " +
                    "He also completed 'The Art of the Cold Call.' " +
                    "Bruce is a member of Toastmasters International."
                )
            );

            this.employeeList[0].OrderList.Add(new Order("Supplier 1", DateTime.Now           , "TV"        , 20));
            this.employeeList[0].OrderList.Add(new Order("Supplier 2", DateTime.Now.AddDays(3), "Projector" , 15));
            this.employeeList[0].OrderList.Add(new Order("Supplier 3", DateTime.Now.AddDays(3), "HDMI Cable", 50));

            this.employeeList.Add
            (
                new Employee
                (
                    "Cindy",
                    "Haneline",
                    "Vice President of Sales",
                    "Cindy received her BTS commercial in 1974 and a Ph.D. " +
                    "in international marketing from the University of Dallas in 1981. " +
                    "She is fluent in French and Italian and reads German. " +
                    "She joined the company as a sales representative, " +
                    "was promoted to sales manager in January 1992 and to vice president of sales in March 1993. " +
                    "Cindy is a member of the Sales Management Roundtable, " +
                    "the Seattle Chamber of Commerce, and the Pacific Rim Importers Association."
                )
            );

            this.employeeList[1].OrderList.Add(new Order("Supplier 1", DateTime.Now.AddDays(1), "Blu-Ray Player", 10));
            this.employeeList[1].OrderList.Add(new Order("Supplier 2", DateTime.Now.AddDays(1), "Blu-Ray Player", 10));
            this.employeeList[1].OrderList.Add(new Order("Supplier 3", DateTime.Now.AddDays(1), "Blu-Ray Player", 10));
            this.employeeList[1].OrderList.Add(new Order("Supplier 4", DateTime.Now.AddDays(1), "Blu-Ray Player", 10));

            this.employeeList.Add
            (
                new Employee
                (
                    "Jack",
                    "Lee",
                    "Sales Manager",
                    "Education includes a BA in psychology from Colorado State University in 1970. " +
                    "He also completed 'The Art of the Cold Call.' " +
                    "Jack is a member of Toastmasters International."
                )
            );

            this.employeeList[2].OrderList.Add(new Order("Supplier 1", DateTime.Now           , "AV Receiver", 20));
            this.employeeList[2].OrderList.Add(new Order("Supplier 2", DateTime.Now.AddDays(3), "Projector"  , 15));

            this.employeeList.Add
            (
                new Employee
                (
                    "Cindy",
                    "Johnson",
                    "Vice President of Sales",
                    "Cindy received her BTS commercial in 1974 and a Ph.D. " +
                    "in international marketing from the University of Dallas in 1981. " +
                    "She is fluent in French and Italian and reads German. " +
                    "She joined the company as a sales representative, " +
                    "was promoted to sales manager in January 1992 and to vice president of sales in March 1993. " +
                    "Cindy is a member of the Sales Management Roundtable, " +
                    "the Seattle Chamber of Commerce, and the Pacific Rim Importers Association."
                )
            );
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요