■ GridControl 클래스에서 마스터 행을 확장하거나 축소하는 방법을 보여준다.
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
<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> |
▶ MainWindow.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
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 } } |