コード例 #1
0
ファイル: Form1.cs プロジェクト: syncfusion/winforms-demos
        /// <summary>
        /// Sets the sample customization settings.
        /// </summary>
        private void SampleCustomization()
        {
            #region SfDataGrid settings
            sfDataGrid1.ThemeName                = "Office2016Colorful";
            sfDataGrid1.ShowRowHeader            = true;
            sfDataGrid1.AllowFiltering           = true;
            this.sfDataGrid1.AllowGrouping       = true;
            this.sfDataGrid1.ShowGroupDropArea   = true;
            this.sfDataGrid1.AutoGenerateColumns = false;
            this.sfDataGrid1.AutoSizeColumnsMode = AutoSizeColumnsMode.Fill;

            OrderInfoRepository orderInfo = new OrderInfoRepository();
            this.sfDataGrid1.DataSource = orderInfo.GetOrdersDetails(30);
            this.sfDataGrid1.Columns.Add(new GridNumericColumn()
            {
                MappingName = "OrderID", HeaderText = "Order ID", Width = 130, NumberFormatInfo = new System.Globalization.NumberFormatInfo {
                    NumberGroupSeparator = "", NumberDecimalDigits = 0
                }
            });
            this.sfDataGrid1.Columns.Add(new GridTextColumn()
            {
                MappingName = "CustomerID", HeaderText = "Customer ID"
            });
            this.sfDataGrid1.Columns.Add(new GridTextColumn()
            {
                MappingName = "ShipCity", HeaderText = "Ship City"
            });
            this.sfDataGrid1.Columns.Add(new GridTextColumn()
            {
                MappingName = "ShipCity", HeaderText = "Ship Country"
            });
            this.sfDataGrid1.Columns.Add(new GridDateTimeColumn()
            {
                MappingName = "ShippingDate", HeaderText = "Shipping Date"
            });
            this.sfDataGrid1.Columns.Add(new GridNumericColumn()
            {
                MappingName = "Freight", HeaderText = "Freight", FormatMode = FormatMode.Currency
            });
            this.sfDataGrid1.Columns.Add(new GridCheckBoxColumn()
            {
                MappingName = "IsClosed", HeaderText = "Is Closed", CheckBoxSize = new Size((int)DpiAware.LogicalToDeviceUnits(14.0f), (int)DpiAware.LogicalToDeviceUnits(14.0f))
            });
            sfDataGrid1.AllowResizingColumns = true;
            #endregion

            #region themComboBox settings
            List <ThemeTypes> theme = new List <ThemeTypes>();
            theme.Add(new ThemeTypes()
            {
                ThemeName = "Office2016Black", Value = 1
            });
            theme.Add(new ThemeTypes()
            {
                ThemeName = "Office2016White", Value = 2
            });
            theme.Add(new ThemeTypes()
            {
                ThemeName = "Office2016DarkGray", Value = 3
            });
            theme.Add(new ThemeTypes()
            {
                ThemeName = "Office2016Colorful", Value = 4
            });
            theme.Add(new ThemeTypes()
            {
                ThemeName = "Office2019Colorful", Value = 5
            });
            theme.Add(new ThemeTypes()
            {
                ThemeName = "HighContrastBlack", Value = 6
            });
            comboBox1.DataSource            = theme;
            comboBox1.DisplayMember         = "ThemeName";
            comboBox1.ValueMember           = "ThemeName";
            comboBox1.SelectedValueChanged += comboBox1_SelectedValueChanged;
            comboBox1.SelectedValue         = "Office2016Colorful";
            #endregion

            this.checkBox1.Style      = Syncfusion.Windows.Forms.Tools.CheckBoxAdvStyle.Office2016Colorful;
            checkBox1.CheckedChanged += checkBox1_CheckedChanged;

            #region TableSummaryRow

            GridTableSummaryRow tableSummaryRow1 = new GridTableSummaryRow();
            tableSummaryRow1.Name             = "TableSummary";
            tableSummaryRow1.ShowSummaryInRow = true;
            tableSummaryRow1.Title            = " Total Count: {OrderID}";
            tableSummaryRow1.Position         = VerticalPosition.Bottom;

            GridSummaryColumn summaryColumn1 = new GridSummaryColumn();
            summaryColumn1.Name        = "OrderID";
            summaryColumn1.SummaryType = SummaryType.DoubleAggregate;
            summaryColumn1.Format      = "{Count}";
            summaryColumn1.MappingName = "OrderID";
            tableSummaryRow1.SummaryColumns.Add(summaryColumn1);
            this.sfDataGrid1.TableSummaryRows.Add(tableSummaryRow1);

            #endregion

            #region GroupSummaryRow

            // Creates the GridSummaryRow.
            GridSummaryRow groupSummaryRow1 = new GridSummaryRow();
            groupSummaryRow1.Name             = "GroupSummary";
            groupSummaryRow1.ShowSummaryInRow = false;
            groupSummaryRow1.Title            = "Total  $: { OrderID }";

            // Creates the GridSummaryColumn.
            GridSummaryColumn summaryColumn3 = new GridSummaryColumn();
            summaryColumn3.Name        = "OrderID";
            summaryColumn3.SummaryType = SummaryType.DoubleAggregate;
            summaryColumn3.Format      = "Total : {Sum:c}";
            summaryColumn3.MappingName = "OrderID";

            // Adds the GridSummaryColumn in SummaryColumns collection.
            groupSummaryRow1.SummaryColumns.Add(summaryColumn3);

            // Adds the summary row in the GroupSummaryRows collection.
            this.sfDataGrid1.GroupSummaryRows.Add(groupSummaryRow1);


            #endregion

            #region Relation Creation
            GridViewDefinition viewDefinition = new GridViewDefinition();
            viewDefinition.RelationalColumn = "OrderDetails";
            firstLevelSourceDataGrid        = new SfDataGrid();
            firstLevelSourceDataGrid.Columns.Add(new GridNumericColumn()
            {
                MappingName = "OrderID", HeaderText = "Order ID", NumberFormatInfo = new System.Globalization.NumberFormatInfo {
                    NumberGroupSeparator = "", NumberDecimalDigits = 0
                }
            });
            firstLevelSourceDataGrid.Columns.Add(new GridDateTimeColumn()
            {
                MappingName = "OrderDate", HeaderText = "Order Date"
            });
            firstLevelSourceDataGrid.Columns.Add(new GridTextColumn()
            {
                MappingName = "CustomerID", HeaderText = "Customer ID"
            });
            firstLevelSourceDataGrid.Columns.Add(new GridTextColumn()
            {
                MappingName = "CustomerCity", HeaderText = "Customer City"
            });
            firstLevelSourceDataGrid.Columns.Add(new GridNumericColumn()
            {
                MappingName = "ProductID", HeaderText = "Product ID", FormatMode = FormatMode.Numeric
            });
            firstLevelSourceDataGrid.Columns.Add(new GridNumericColumn()
            {
                MappingName = "UnitPrice", HeaderText = "Unit Price", FormatMode = FormatMode.Currency
            });
            firstLevelSourceDataGrid.Columns.Add(new GridNumericColumn()
            {
                MappingName = "Quantity", HeaderText = "Quantity", FormatMode = FormatMode.Numeric
            });
            firstLevelSourceDataGrid.Columns.Add(new GridNumericColumn()
            {
                MappingName = "Discount", HeaderText = "Discount", FormatMode = FormatMode.Percent
            });
            StackedHeaderRow stackedHeaderRow = new StackedHeaderRow();
            stackedHeaderRow.StackedColumns.Add(new StackedColumn()
            {
                ChildColumns = "OrderID,OrderDate", HeaderText = "Order Details"
            });
            stackedHeaderRow.StackedColumns.Add(new StackedColumn()
            {
                ChildColumns = "CustomerID,CustomerCity", HeaderText = "Customer Details"
            });
            stackedHeaderRow.StackedColumns.Add(new StackedColumn()
            {
                ChildColumns = "ProductID,UnitPrice,Quantity,Discount", HeaderText = "Product Details"
            });
            firstLevelSourceDataGrid.AllowResizingColumns = true;
            firstLevelSourceDataGrid.AutoSizeColumnsMode  = AutoSizeColumnsMode.Fill;
            viewDefinition.DataGrid = firstLevelSourceDataGrid;
            this.sfDataGrid1.DetailsViewDefinitions.Add(viewDefinition);
            #endregion

            this.sfDataGrid1.HideEmptyGridViewDefinition = true;
        }