반응형
c# code로 grid column 생성.


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 | < Page xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc = "http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d = "http://schemas.microsoft.com/expression/blend/2008" xmlns:local = "clr-namespace:WpfSample.DevTest" xmlns:dxlc = "http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol" xmlns:dx = "http://schemas.devexpress.com/winfx/2008/xaml/core" xmlns:Serialization = "clr-namespace:DevExpress.Xpf.LayoutControl.Serialization;assembly=DevExpress.Xpf.LayoutControl.v17.2" xmlns:dxe = "http://schemas.devexpress.com/winfx/2008/xaml/editors" xmlns:dxg = "http://schemas.devexpress.com/winfx/2008/xaml/grid" x:Class = "WpfSample.DevTest.Grid13DynamicAddColumns" mc:Ignorable = "d" d:DesignHeight = "800" d:DesignWidth = "1280" Title = "Grid01" > < StackPanel Margin = "0,10,10,10" > < dxlc:LayoutControl HorizontalAlignment = "Stretch" VerticalAlignment = "Stretch" Orientation = "Vertical" > < dxlc:LayoutGroup Header = "Button" View = "GroupBox" HorizontalAlignment = "Stretch" > < dx:SimpleButton x:Name = "btnSearch" Content = "Search" HorizontalAlignment = "Left" Click = "Button_Click" /> </ dxlc:LayoutGroup > </ dxlc:LayoutControl > < dxlc:LayoutControl HorizontalAlignment = "Stretch" VerticalAlignment = "Stretch" Orientation = "Vertical" > < dxlc:LayoutGroup Header = "Grid" View = "GroupBox" HorizontalAlignment = "Stretch" Height = "500" > < dxg:GridControl x:Name = "gcGrid" SelectionMode = "Cell" > < dxg:GridControl.Columns > </ dxg:GridControl.Columns > < dxg:GridControl.View > < dxg:TableView x:Name = "tvView" AllowScrollAnimation = "True" AllowEditing = "False" /> </ dxg:GridControl.View > </ dxg:GridControl > </ dxlc:LayoutGroup > </ dxlc:LayoutControl > </ StackPanel > </ Page > |
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 | using System; using System.Collections.Generic; using System.Windows; using System.Windows.Controls; using DevExpress.Xpf.Grid; using BIZ.Common.Dac; namespace WpfSample.DevTest { /// <summary> /// Grid13DynamicAddColumns.xaml에 대한 상호 작용 논리 /// </summary> public partial class Grid13DynamicAddColumns : Page { public Grid13DynamicAddColumns() { InitializeComponent(); //GetBindGrid(); } private void CreateGridColumn() { CreateColumn( "SalesOrderID" , "SalesOrderID" ); CreateColumn( "CustomerID" , "CustomerID" ); CreateColumn( "RevisionNumber" , "RevisionNumber" ); CreateColumn( "OrderDate" , "OrderDate" ); CreateColumn( "DueDate" , "DueDate" ); CreateColumn( "ShipDate" , "ShipDate" ); CreateColumn( "Status" , "Status" ); CreateColumn( "OnlineOrderFlag" , "OnlineOrderFlag" ); CreateColumn( "SalesOrderNumber" , "SalesOrderNumber" ); CreateColumn( "PurchaseOrderNumber" , "PurchaseOrderNumber" ); CreateColumn( "AccountNumber" , "AccountNumber" ); CreateColumn( "CustomerID" , "CustomerID" ); CreateColumn( "SalesPersonID" , "SalesPersonID" ); CreateColumn( "TerritoryID" , "TerritoryID" ); CreateColumn( "BillToAddressID" , "BillToAddressID" ); CreateColumn( "ShipToAddressID" , "ShipToAddressID" ); CreateColumn( "ShipMethodID" , "ShipMethodID" ); CreateColumn( "CreditCardID" , "CreditCardID" ); CreateColumn( "CreditCardApprovalCode" , "CreditCardApprovalCode" ); CreateColumn( "CurrencyRateID" , "CurrencyRateID" ); CreateColumn( "SubTotal" , "SubTotal" ); CreateColumn( "TaxAmt" , "TaxAmt" ); CreateColumn( "Freight" , "Freight" ); CreateColumn( "TotalDue" , "TotalDue" ); CreateColumn( "Comment" , "Comment" ); CreateColumn( "ModifiedDate" , "ModifiedDate" ); } private void GetBindGrid() { Dictionary< string , object > dic = new Dictionary< string , object >(); dic.Add( "param1" , "111" ); var data = ( new ADOConnect()).GetDataSet( "AdventureWorks2016" , "Z_UP_SALES_ORDER2_LIST" , dic); CreateGridColumn(); gcGrid.ItemsSource = data.Tables[0]; } private void Button_Click( object sender, RoutedEventArgs e) { GetBindGrid(); } private void CreateColumn( string fieldName, string header) { GridColumn gc = new GridColumn(); gc.FieldName = fieldName; gc.Header = header; gcGrid.Columns.Add(gc); } } } |
반응형
'WPF - DevExpress' 카테고리의 다른 글
WPF & DevExpress TreeView (0) | 2021.04.10 |
---|---|
WPF & DevExpress GridControl Master Detail Grid current data row (2) | 2021.04.04 |
WPF & DevExpress GridControl Column Fixed (6) | 2021.04.03 |
WPF & DevExpress GridControl Context Menu (4) | 2021.04.02 |
WPF & DevExpress GridControl Move to next cell (6) | 2021.04.01 |
댓글