private void GridSettings() { dataSet1 = new DataSet(); ReadXml(dataSet1, @"Data\Expand.xml"); dataSet1.Tables[1].TableName = "Products"; dataSet1.Tables[2].TableName = "OrderDetails"; dataSet1.Tables[3].TableName = "Suppliers"; dataSet1.Relations.Add( dataSet1.Tables[0].Columns["CategoryID"], dataSet1.Tables[1].Columns["CategoryID"]); dataSet1.Relations[0].RelationName = "Category_Products"; dataSet1.Relations.Add( dataSet1.Tables[1].Columns["ProductID"], dataSet1.Tables[2].Columns["ProductID"]); dataSet1.Relations[1].RelationName = "Products_OrderDetails"; this.gridGroupingControl1.DataSource = dataSet1.Tables[0]; this.gridGroupingControl1.ThemesEnabled = true; this.gridGroupingControl1.GridVisualStyles = Syncfusion.Windows.Forms.GridVisualStyles.Metro; this.gridGroupingControl1.ShowGroupDropArea = true; this.gridGroupingControl1.TableDescriptor.Appearance.AnyCell.Font.Facename = "Segoe UI"; this.gridGroupingControl1.TableDescriptor.Appearance.AnyCell.Font.Size = 10f; #region Summaries GridTableDescriptor categoriesTableDescriptor = (GridTableDescriptor)this.gridGroupingControl1.Engine.TableDescriptor; //Creating a new SummaryColumnDescriptor. GridSummaryColumnDescriptor countCat = new GridSummaryColumnDescriptor(); //Setting it's properties. countCat.SummaryType = SummaryType.Count; //Initializing it to the Column it is associated with. countCat.DataMember = "CategoryID"; //Adding the SummaryColumnDescriptor to the SummaryRowDescriptor. GridSummaryRowDescriptor categoriesSummaryRow = new GridSummaryRowDescriptor(); categoriesSummaryRow.SummaryColumns.Add(countCat); //Adding the SummaryRowDescriptor to the TableDesriptor. categoriesTableDescriptor.SummaryRows.Add(categoriesSummaryRow); #endregion // expand a specific record, search for groups etc. Table categoriesTable = this.gridGroupingControl1.Engine.Table; Table productsTable = categoriesTable.RelatedTables["Products"]; this.gridGroupingControl1.ShowGroupDropArea = true; this.gridGroupingControl1.Table.Records[0].IsExpanded = true; categoriesTable.Records[0].IsExpanded = true; //Navigate to other control using tabkey navigation this.gridGroupingControl1.WantTabKey = false; #region Setting Header Text this.gridGroupingControl1.TableDescriptor.Columns["CategoryID"].HeaderText = "Category ID"; this.gridGroupingControl1.TableDescriptor.Columns["CategoryName"].HeaderText = "Category Name"; GridTableDescriptor childTableDescriptor = this.gridGroupingControl1.GetTableDescriptor("Products"); childTableDescriptor.Columns["ProductID"].HeaderText = "Product ID"; childTableDescriptor.Columns["ProductName"].HeaderText = "Product Name"; childTableDescriptor.Columns["UnitsInStock"].HeaderText = "Units In Stock"; childTableDescriptor.Columns["ReorderLevel"].HeaderText = "Reorder Level"; childTableDescriptor.Columns["QuantityPerUnit"].HeaderText = "Quantity Per Unit"; childTableDescriptor.Columns["UnitPrice"].HeaderText = "Unit Price"; childTableDescriptor.Columns["UnitsOnOrder"].HeaderText = "Unit on Order"; GridTableDescriptor nestedTableDescriptor = this.gridGroupingControl1.GetTableDescriptor("OrderDetails"); nestedTableDescriptor.Columns["OrderID"].HeaderText = "Order ID"; nestedTableDescriptor.Columns["UnitPrice"].HeaderText = "Unit price"; #endregion }
/// <summary> /// SortBySummaryInCaption sample Customizations /// </summary> private void SampleCustomization() { InitializeDataSet(); GridTableDescriptor ordersDescriptor = this.gridGroupingControl1.TableDescriptor; // You can define a summary row and mark it hidden. // In that summary row you can add a column and set it's mapping name (and DisplayColumn) to be Freight GridSummaryColumnDescriptor summaryColumn1 = new GridSummaryColumnDescriptor("FreightAverage", SummaryType.DoubleAggregate, "Freight", "{Average:###.00}"); GridSummaryRowDescriptor summaryRow1 = new GridSummaryRowDescriptor(); summaryRow1.Name = "Caption"; summaryRow1.Visible = false; summaryRow1.SummaryColumns.Add(summaryColumn1); ordersDescriptor.SummaryRows.Add(summaryRow1); // This is a second row, not marked hidden and therefore shown at the end of the group. GridSummaryColumnDescriptor summaryColumn2 = new GridSummaryColumnDescriptor("FreightTotal", SummaryType.DoubleAggregate, "Freight", "{Average:###.00}"); GridSummaryRowDescriptor summaryRow2 = new GridSummaryRowDescriptor(); summaryRow2.Name = "Bottom"; summaryRow2.Visible = true; summaryRow2.SummaryColumns.Add(summaryColumn2); ordersDescriptor.SummaryRows.Add(summaryRow2); // Here you define the summary row that should be used for displaying summaries in caption bar. ordersDescriptor.ChildGroupOptions.ShowCaptionSummaryCells = true; ordersDescriptor.ChildGroupOptions.CaptionSummaryRow = "Caption"; // Let's you hide/show the second row in child groups. ordersDescriptor.ChildGroupOptions.ShowSummaries = false; // Move Freight column ahead // ordersDescriptor.VisibleColumns.LoadDefault(); int count = ordersDescriptor.VisibleColumns.Count; // force populating VisibleColumns ordersDescriptor.VisibleColumns.Remove("Freight"); ordersDescriptor.VisibleColumns.Insert(3, new GridVisibleColumnDescriptor("Freight")); // Minor customization: Have Caption bar cover some cells. this.gridGroupingControl1.TableModel.QueryCoveredRange += new GridQueryCoveredRangeEventHandler(TableModel_QueryCoveredRange); captionCoverCols = 2; this.gridGroupingControl1.Appearance.GroupCaptionCell.BackColor = this.gridGroupingControl1.Appearance.RecordFieldCell.BackColor; this.gridGroupingControl1.Appearance.GroupCaptionCell.Borders.Top = new GridBorder(GridBorderStyle.Standard); this.gridGroupingControl1.Appearance.GroupCaptionCell.CellType = "Static"; this.gridGroupingControl1.TableOptions.CaptionRowHeight = this.gridGroupingControl1.TableOptions.RecordRowHeight; this.gridGroupingControl1.ChildGroupOptions.ShowAddNewRecordBeforeDetails = false; // Specify group sort order behavoir when adding SortColumnDescriptor to GroupedColumns this.gridGroupingControl1.TableDescriptor.GroupedColumns.Clear(); SortColumnDescriptor gsd = new SortColumnDescriptor("ShipCountry"); // specify your own Comparer //gsd.GroupSortOrderComparer = new ShipViaComparer(summaryColumn1.GetSummaryDescriptorName(), "Average"); // or specify a summary name and the property (values will be determined using reflection) gsd.SetGroupSummarySortOrder(summaryColumn1.GetSummaryDescriptorName(), "Average"); this.gridGroupingControl1.TableDescriptor.GroupedColumns.Add(gsd); // this should always be true since changing one record can cause the whole group to move // to a different position. this.gridGroupingControl1.InvalidateAllWhenListChanged = true; foreach (GridColumnDescriptor col in this.gridGroupingControl1.TableDescriptor.Columns) { System.Text.RegularExpressions.Regex rex = new System.Text.RegularExpressions.Regex(@"\p{Lu}"); int index = rex.Match(col.MappingName.Substring(1)).Index; string name = ""; while (index > 0) { name += col.MappingName.Substring(0, index + 1) + " "; string secondName = col.MappingName.Substring(index + 1); index = rex.Match(secondName.Substring(1)).Index; while (index > 0) { name += secondName.Substring(0, index + 1) + " "; index = rex.Match(col.MappingName.Substring(name.Replace(" ", "").Length).Substring(1)).Index; } } name += col.MappingName.Substring(name.Replace(" ", "").Length); col.HeaderText = name; } }
/// <summary> /// Grid Settings for better Look and Feel. /// </summary> private void GridSettings() { GridTableDescriptor ordersDescriptor = this.gridGroupingControl1.TableDescriptor; // Add Unbound ordersDescriptor.UnboundFields.Add("ShipVia_CompanyName"); // Callback for conversion ordersDescriptor.QueryValue += new FieldValueEventHandler(ordersDescriptor_QueryValue); // Hide it. ordersDescriptor.VisibleColumns.Remove("ShipVia_CompanyName"); // Use it for grouping. ordersDescriptor.GroupedColumns.Add("ShipVia_CompanyName"); ordersDescriptor.TopLevelGroupOptions.ShowCaptionSummaryCells = false; // not neeeded. ordersDescriptor.PrimaryKeyColumns.Clear(); // You can define a summary row and mark it hidden. // In that summary row you can add a column and set it's mapping name (and DisplayColumn) to be Freight GridSummaryColumnDescriptor summaryColumn1 = new GridSummaryColumnDescriptor("FreightAverage", SummaryType.DoubleAggregate, "Freight", "{Average:###.00}"); GridSummaryRowDescriptor summaryRow1 = new GridSummaryRowDescriptor(); summaryRow1.Name = "Caption"; summaryRow1.Visible = false; summaryRow1.SummaryColumns.Add(summaryColumn1); ordersDescriptor.SummaryRows.Add(summaryRow1); // This is a second row, not marked hidden and therefore shown at the end of the group. GridSummaryColumnDescriptor summaryColumn2 = new GridSummaryColumnDescriptor("FreightTotal", SummaryType.DoubleAggregate, "Freight", "{Average:###.00}"); GridSummaryRowDescriptor summaryRow2 = new GridSummaryRowDescriptor(); summaryRow2.Name = "Bottom"; summaryRow2.Visible = true; summaryRow2.SummaryColumns.Add(summaryColumn2); ordersDescriptor.SummaryRows.Add(summaryRow2); // Here you define the summary row that should be used for displaying summaries in caption bar. ordersDescriptor.ChildGroupOptions.ShowCaptionSummaryCells = true; ordersDescriptor.ChildGroupOptions.ShowSummaries = true; ordersDescriptor.ChildGroupOptions.CaptionSummaryRow = "Caption"; // Let's you hide/show the second row in child groups. ordersDescriptor.ChildGroupOptions.ShowSummaries = false; // Move Freight column ahead // ordersDescriptor.VisibleColumns.LoadDefault(); int count = ordersDescriptor.VisibleColumns.Count; // force populating VisibleColumns ordersDescriptor.VisibleColumns.Remove("Freight"); ordersDescriptor.VisibleColumns.Insert(3, new GridVisibleColumnDescriptor("Freight")); // Minor customization: Have Caption bar cover some cells. this.gridGroupingControl1.TableModel.QueryCoveredRange += new GridQueryCoveredRangeEventHandler(TableModel_QueryCoveredRange); captionCoverCols = 2; this.gridGroupingControl1.Appearance.GroupCaptionCell.BackColor = this.gridGroupingControl1.Appearance.RecordFieldCell.BackColor; this.gridGroupingControl1.Appearance.GroupCaptionCell.Borders.Top = new GridBorder(GridBorderStyle.Standard); this.gridGroupingControl1.Appearance.GroupCaptionCell.CellType = "Static"; this.gridGroupingControl1.TableDescriptor.Appearance.AnyHeaderCell.Font.Bold = true; this.gridGroupingControl1.TableOptions.CaptionRowHeight = this.gridGroupingControl1.TableOptions.RecordRowHeight; this.gridGroupingControl1.ChildGroupOptions.ShowAddNewRecordBeforeDetails = false; gridGroupingControl1.Table.CurrentRecord = gridGroupingControl1.Table.Records[0]; this.gridGroupingControl1.TableOptions.GridVisualStyles = Syncfusion.Windows.Forms.GridVisualStyles.Office2007Blue; this.gridGroupingControl1.TableOptions.GridLineBorder = new Syncfusion.Windows.Forms.Grid.GridBorder(GridBorderStyle.Solid, Color.FromArgb(208, 215, 229), GridBorderWeight.Thin); this.gridGroupingControl1.TopLevelGroupOptions.ShowAddNewRecordBeforeDetails = false; this.gridGroupingControl1.TopLevelGroupOptions.ShowCaption = false; gridGroupingControl1.Appearance.AnyCell.Font.Facename = "Segoe UI"; this.BackColor = Color.FromArgb(223, 227, 239); this.gridGroupingControl1.GridVisualStyles = GridVisualStyles.Metro; this.propertyGrid1.SelectedObject = this.gridGroupingControl1; this.propertyGrid1.BackColor = Color.White; //Navigate to other control using tabkey navigation this.gridGroupingControl1.WantTabKey = false; t.Tick += new EventHandler(t_Tick); foreach (GridColumnDescriptor col in this.gridGroupingControl1.TableDescriptor.Columns) { Regex rex = new Regex(@"\p{Lu}"); int index = rex.Match(col.MappingName.Substring(1)).Index; string name = ""; while (index > 0) { name += col.MappingName.Substring(0, index + 1) + " "; string secondName = col.MappingName.Substring(index + 1); index = rex.Match(secondName.Substring(1)).Index; while (index > 0) { name += secondName.Substring(0, index + 1) + " "; index = rex.Match(col.MappingName.Substring(name.Replace(" ", "").Length).Substring(1)).Index; } } name += col.MappingName.Substring(name.Replace(" ", "").Length); col.HeaderText = name; } }
/// <summary> /// GridGrouping control getting started customization. /// </summary> private void GridSettings() { #region "Data Source" String commandstring1 = "select * from Customers"; String commandstring2 = "select * from Orders"; this.dataSet11 = new EnhancedVisualStyleInGGCDemo_2005.DataSet1(); this.dataSet11.DataSetName = "DataSet1"; this.dataSet11.Locale = new System.Globalization.CultureInfo("en-US"); this.dataSet11.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema; SqlCeDataAdapter da1 = new SqlCeDataAdapter(commandstring1, connString); SqlCeDataAdapter da2 = new SqlCeDataAdapter(commandstring2, connString); da1.Fill(dataSet11, "Customers"); da1.Fill(dataSet11, "Orders"); //used to set multiextended selection mode in gridgrouping control. this.gridGroupingControl1.TableOptions.ListBoxSelectionMode = SelectionMode.MultiExtended; //used to set GridCaptionRowHeight. this.gridGroupingControl1.Table.DefaultCaptionRowHeight = 25; this.gridGroupingControl1.Table.DefaultColumnHeaderRowHeight = 30; this.gridGroupingControl1.Table.DefaultRecordRowHeight = 22; this.MetroColor = System.Drawing.Color.Transparent; this.gridGroupingControl1.DataSource = this.dataSet11.Customers; this.gridGroupingControl1.DataSource = this.dataSet11.Tables["Customers"]; this.gridGroupingControl1.AddGroupDropArea("Orders"); #endregion //Enable the filter for each columns for (int i = 0; i < gridGroupingControl1.TableDescriptor.Columns.Count; i++) { gridGroupingControl1.TableDescriptor.Columns[i].AllowFilter = true; } GridTableDescriptor childDesc = gridGroupingControl1.GetTableDescriptor("Orders"); for (int j = 0; j < childDesc.Columns.Count; j++) { childDesc.Columns[j].AllowFilter = true; } this.gridGroupingControl1.TableModel.EnableLegacyStyle = false; this.gridGroupingControl1.GridVisualStyles = GridVisualStyles.Metro; //Enable dynamic filter. filter.WireGrid(gridGroupingControl1); this.gridGroupingControl1.TopLevelGroupOptions.ShowAddNewRecordBeforeDetails = false; this.gridGroupingControl1.TopLevelGroupOptions.ShowCaption = false; this.gridGroupingControl1.NestedTableGroupOptions.ShowAddNewRecordBeforeDetails = false; this.gridGroupingControl1.TopLevelGroupOptions.ShowFilterBar = true; this.gridGroupingControl1.NestedTableGroupOptions.ShowFilterBar = true; this.gridGroupingControl1.ChildGroupOptions.ShowFilterBar = true; this.gridGroupingControl1.TableDescriptor.Columns["CompanyName"].HeaderText = "Company Name"; this.gridGroupingControl1.TableDescriptor.Columns["ContactName"].HeaderText = "Contact Name"; this.gridGroupingControl1.TableDescriptor.Columns["ContactTitle"].HeaderText = "Contact Title"; this.gridGroupingControl1.TableDescriptor.Columns["PostalCode"].HeaderText = "Postal Code"; this.gridGroupingControl1.GetTableDescriptor("Orders").Columns["ShipVia"].HeaderText = "Ship Via"; this.gridGroupingControl1.GetTableDescriptor("Orders").Columns["ShipRegion"].HeaderText = "Ship Region"; this.gridGroupingControl1.GetTableDescriptor("Orders").Columns["ShipPostalCode"].HeaderText = "Ship Postal Code"; this.gridGroupingControl1.GetTableDescriptor("Orders").Columns["ShippedDate"].HeaderText = "Shipped Date"; this.gridGroupingControl1.GetTableDescriptor("Orders").Columns["ShipName"].HeaderText = "Ship Name"; this.gridGroupingControl1.GetTableDescriptor("Orders").Columns["ShipCountry"].HeaderText = "Ship Country"; this.gridGroupingControl1.GetTableDescriptor("Orders").Columns["ShipCity"].HeaderText = "Ship City"; this.gridGroupingControl1.GetTableDescriptor("Orders").Columns["ShipAddress"].HeaderText = "Ship Address"; this.gridGroupingControl1.GetTableDescriptor("Orders").Columns["RequiredDate"].HeaderText = "Required Date"; this.gridGroupingControl1.GetTableDescriptor("Orders").Columns["OrderID"].HeaderText = "Order ID"; this.gridGroupingControl1.GetTableDescriptor("Orders").Columns["OrderDate"].HeaderText = "Order Date"; this.gridGroupingControl1.GetTableDescriptor("Orders").Columns["EmployeeID"].HeaderText = "Employee ID"; }
/// <summary> /// Setting Maual relation to the GridGroupingControl. /// </summary> private void SampleCustomization() { #region DataTable DataSet ds = new DataSet(); ReadXml(ds, @"Expand.xml"); ds.Tables[1].TableName = "Products"; ds.Tables[2].TableName = "OrderDetails"; ds.Tables[3].TableName = "Suppliers"; ds.Relations.Add( ds.Tables[0].Columns["CategoryID"], ds.Tables[1].Columns["CategoryID"]); ds.Relations[0].RelationName = "Category_Products"; ds.Relations.Add( ds.Tables[1].Columns["ProductID"], ds.Tables[2].Columns["ProductID"]); ds.Relations[1].RelationName = "Products_OrderDetails"; #endregion this.groupingGrid1.DataSource = ds.Tables[0]; GridEngine engine = this.groupingGrid1.Engine; engine.TopLevelGroupOptions.ShowCaption = true; // Record summary for Categories Tables GridTableDescriptor categoriesTableDescriptor = (GridTableDescriptor)engine.TableDescriptor; categoriesTableDescriptor.Columns.Clear(); categoriesTableDescriptor.Columns.Add("CategoryID"); categoriesTableDescriptor.Columns.Add("CategoryName"); categoriesTableDescriptor.Columns.Add("Description"); categoriesTableDescriptor.Columns["CategoryName"].Width = 200; //Creating a new SummaryColumnDescriptor. GridSummaryColumnDescriptor countCat = new GridSummaryColumnDescriptor("RecordCount"); //Setting it's properties. countCat.SummaryType = SummaryType.Count; countCat.Style = GridSummaryStyle.FillRow; //Initializing it to the Column it is associated with. countCat.DataMember = "CategoryID"; //Mentioning the format of display. countCat.Format = " {Count} Records."; //Adding the SummaryColumnDescriptor to the SummaryRowDescriptor. GridSummaryRowDescriptor categoriesSummaryRow = new GridSummaryRowDescriptor("RecordCountRow"); categoriesSummaryRow.SummaryColumns.Add(countCat); //Adding the SummaryRowDescriptor to the TableDesriptor. categoriesTableDescriptor.SummaryRows.Add(categoriesSummaryRow); // Group Products table by "SupplierID" RelationDescriptor productsRelationDescriptor = categoriesTableDescriptor.Relations["Products"]; GridTableDescriptor productsTableDescriptor = (GridTableDescriptor)productsRelationDescriptor.ChildTableDescriptor; productsTableDescriptor.GroupedColumns.Add("SupplierID"); // Group OrderDetails table by "Discount" // Add Total = "[UnitPrice]*[Quantity]" expression field // Add Summaries for Total and Average for UnitPrice. RelationDescriptor orderDetailsRelationDescriptor = productsTableDescriptor.Relations["OrderDetails"]; GridTableDescriptor orderDetailsTableDescriptor = (GridTableDescriptor)orderDetailsRelationDescriptor.ChildTableDescriptor; ExpressionFieldDescriptor ed = new ExpressionFieldDescriptor("Total", "[UnitPrice]*[Quantity]"); ed.DefaultValue = ""; orderDetailsTableDescriptor.ExpressionFields.Add(ed); orderDetailsTableDescriptor.GroupedColumns.Add("Discount"); //Adding the SummaryColumnDescriptor to the SummaryRowDescriptor. GridSummaryRowDescriptor orderDetailsSummaryRow = new GridSummaryRowDescriptor("Total"); orderDetailsTableDescriptor.SummaryRows.Add(orderDetailsSummaryRow); //Creating a new SummaryColumnDescriptor. GridSummaryColumnDescriptor totalSum = new GridSummaryColumnDescriptor("Total"); //Setting it's properties. totalSum.SummaryType = SummaryType.DoubleAggregate; totalSum.Style = GridSummaryStyle.Column; //Initializing it to the Column it is associated with. totalSum.DataMember = "Total"; totalSum.DisplayColumn = "Total"; totalSum.Format = "Sum={Sum}"; orderDetailsSummaryRow.SummaryColumns.Add(totalSum); orderDetailsTableDescriptor.Columns["Total"].Width = 70; //Creating a new SummaryColumnDescriptor. GridSummaryColumnDescriptor avgUnitPrice = new GridSummaryColumnDescriptor("AvgUnitPrice"); //Setting it's properties. avgUnitPrice.SummaryType = SummaryType.DoubleAggregate; avgUnitPrice.Style = GridSummaryStyle.Column; avgUnitPrice.DataMember = "UnitPrice"; avgUnitPrice.DisplayColumn = "UnitPrice"; avgUnitPrice.Format = "Avg={Average:#.0}"; orderDetailsSummaryRow.SummaryColumns.Add(avgUnitPrice); // expand a specific record, search for groups etc. Table categoriesTable = engine.Table;//.RelatedTables["Categories"]; Console.WriteLine(categoriesTable.ToString()); Table productsTable = categoriesTable.RelatedTables["Products"]; Console.WriteLine(productsTable.ToString()); // Get the child table in the products table that is assocuated with category "1" ChildTable product1 = (ChildTable)productsTable.TopLevelGroup.Groups["1"]; Console.WriteLine(product1.ToString()); Console.WriteLine(product1.Groups[0].ToString()); // Get the child table in the products table that is assocuated with category "1" ChildTable product21 = (ChildTable)productsTable.TopLevelGroup.Groups["8"]; Console.WriteLine(product21.ToString()); Console.WriteLine(product21.Groups[0].Records[0].ToString()); // Show me the associated "NestedTable" element of the categories table (the NestedTable // element established the link between parent table and a nested child table) Console.WriteLine(product21.Groups[0].Records[0].ParentChildTable.ParentNestedTable); // Expand the product for category 8 product21.IsExpanded = true; product21.ParentNestedTable.IsExpanded = true; product21.ParentNestedTable.ParentRecord.IsExpanded = true; // When you assign a "DataSet" as a datasource, the DataSet is a list with one record (not allowing AddNew) with nested tables. // Expand the first record so that tables are shown. engine.Table.TopLevelGroup.Records[0].IsExpanded = true; // Sort product table by ProductName product21.ParentTable.TableDescriptor.SortedColumns.Add("ProductName"); // Find group for supplier id 21 Group supplier21Group = product21.Groups["21"]; // Find productname Spegesild in that group int index = supplier21Group.Records.FindRecord("Spegesild"); // Print out the row index and record index Record r = supplier21Group.Records[index]; Console.WriteLine("Found: " + r.ToString()); Console.WriteLine("RowIndex " + engine.Table.NestedDisplayElements.IndexOf(r).ToString()); Console.WriteLine("Record Index " + engine.Table.Records.IndexOf(r).ToString()); // Dump out nested display elements to console this.groupingGrid1.Table.Records[0].IsExpanded = true; this.groupingGrid1.Table.TopLevelGroup.IsExpanded = true; engine.ChildGroupOptions.ShowCaption = true; engine.NestedTableGroupOptions.ShowCaption = true; // Adding GroupDropAreas for nested tables. groupingGrid1.AddGroupDropArea((GridTable)productsTable); groupingGrid1.AddGroupDropArea((GridTable)productsTable.RelatedTables[0]); groupingGrid1.ShowGroupDropArea = true; //Navigate to other control using tabkey navigation groupingGrid1.WantTabKey = false; // Make Spegesild current record if (r != null) { r.SetCurrent(); // Expand record and nested tables r.IsExpanded = true; r.NestedTables[0].IsExpanded = true; Record orderDetailsRecords = r.NestedTables[0].ChildTable.GetFirstRecord(); // Expand Group record belongs to orderDetailsRecords.ParentGroup.IsExpanded = true; // Scroll this record in view. groupingGrid1.TableControl.ScrollInView(orderDetailsRecords); groupingGrid1.TableControl.LeftColIndex = 1; } }
/// <summary> /// Grid Settings for better Look and Feel /// </summary> private void GridSettings() { this.gridGroupingControl1.Size = new System.Drawing.Size(980, 640); this.gridGroupingControl1.Location = new Point(15, 2); this.gridGroupingControl1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; this.gridGroupingControl1.TableOptions.GridVisualStyles = GridVisualStyles.Metro; this.gridGroupingControl1.TableOptions.GridLineBorder = new GridBorder(GridBorderStyle.Solid, Color.FromArgb(208, 215, 229), GridBorderWeight.Thin); this.gridGroupingControl1.TopLevelGroupOptions.ShowAddNewRecordBeforeDetails = false; this.gridGroupingControl1.TopLevelGroupOptions.ShowCaption = false; this.gridGroupingControl1.Appearance.AnyCell.Font.Facename = "Segoe UI"; GridTableDescriptor td = this.gridGroupingControl1.TableDescriptor; FieldDescriptor unboundFd = new FieldDescriptor("Unbound"); td.UnboundFields.Add(unboundFd); // In case you want to manually add fields here gridGroupingControl1.TableDescriptor.Columns.Clear(); gridGroupingControl1.TableDescriptor.Columns.Add("FooColumn1_PropertyOne"); gridGroupingControl1.TableDescriptor.Columns.Add("FooColumn1_PropertyTwo"); gridGroupingControl1.TableDescriptor.Columns.Add("FooColumn2_SomeProperty"); gridGroupingControl1.TableDescriptor.Columns.Add("FooColumn2_Inner_PropertyOne"); gridGroupingControl1.TableDescriptor.Columns.Add("FooColumn2_Inner_PropertyTwo"); gridGroupingControl1.TableDescriptor.Columns.Add("Boolean"); gridGroupingControl1.TableDescriptor.Columns.Add("Color"); gridGroupingControl1.TableDescriptor.Columns.Add("Font"); gridGroupingControl1.TableDescriptor.Columns.Add("PatternStyle"); gridGroupingControl1.TableDescriptor.Columns.Add("DockStyle"); gridGroupingControl1.TableDescriptor.Columns.Add("FieldDescriptor"); gridGroupingControl1.TableDescriptor.Columns.Add("BordersInfo"); gridGroupingControl1.TableDescriptor.Columns.Add("Unbound"); this.gridGroupingControl1.Dock = DockStyle.Fill; //Adding GridGroupingControl to the form controls this.Controls.Add(gridGroupingControl1); this.gridGroupingControl1.TableControl.DpiAware = true; gridGroupingControl1.SaveValue += new FieldValueEventHandler(grid_SaveValue); gridGroupingControl1.QueryValue += new FieldValueEventHandler(grid_QueryValue); this.gridGroupingControl1.GridVisualStyles = GridVisualStyles.Metro; this.gridGroupingControl1.GridOfficeScrollBars = OfficeScrollBars.Metro; // enable/disable UITYpeEditors for cells. bool showUITypeEditors = true; this.gridGroupingControl1.TableOptions.AllowDropDownCell = showUITypeEditors; this.gridGroupingControl1.TableDescriptor.Columns["Boolean"].Appearance.AnyRecordFieldCell.CellType = "ComboBox"; //Used to set the selction mode for grid this.gridGroupingControl1.TableOptions.ListBoxSelectionMode = SelectionMode.MultiExtended; this.gridGroupingControl1.TableDescriptor.Appearance.AnyHeaderCell.Font.Bold = true; gridGroupingControl1.TableDescriptor.Columns["FooColumn1_PropertyOne"].HeaderText = "Foo Column1_Property One"; gridGroupingControl1.TableDescriptor.Columns["FooColumn1_PropertyTwo"].HeaderText = "Foo Column1_Property Two"; gridGroupingControl1.TableDescriptor.Columns["FooColumn2_SomeProperty"].HeaderText = "Foo Column2_Some Property"; gridGroupingControl1.TableDescriptor.Columns["FooColumn2_Inner_PropertyOne"].HeaderText = "Foo Column2_Inner_Property One"; gridGroupingControl1.TableDescriptor.Columns["FooColumn2_Inner_PropertyTwo"].HeaderText = "Foo Column2_Inner_Property Two"; gridGroupingControl1.TableDescriptor.Columns["PatternStyle"].HeaderText = "Pattern Style"; gridGroupingControl1.TableDescriptor.Columns["DockStyle"].HeaderText = "Dock Style"; gridGroupingControl1.TableDescriptor.Columns["FieldDescriptor"].HeaderText = "Field Descriptor"; gridGroupingControl1.TableDescriptor.Columns["BordersInfo"].HeaderText = "Borders Info"; }
/// <summary> /// Grouping sample Customizations are done here. /// </summary> private void SampleCustomization() { //set up the main table DataTable dt = GetMainDataTable(); DataSet ds = new DataSet("Main"); ds.Tables.Add(dt); this.gridGroupingControl1.DataSource = ds; this.gridGroupingControl1.DataMember = dt.TableName; //remember the location of lookupcol so it can be swapped out later GridTableDescriptor td = this.gridGroupingControl1.TableDescriptor; td.VisibleColumns.LoadDefault(); int lookUpIndex = td.VisibleColumns.IndexOf("Customer"); //get the lookup table DataTable lookUpDataTable = this.GetForeignTable(); DataSet ds2 = new DataSet("LookUp"); ds2.Tables.Add(lookUpDataTable); //add it to the grouping engine this.gridGroupingControl1.Engine.SourceListSet.Add(lookUpDataTable.TableName, lookUpDataTable.DefaultView); //set up relation descriptor that defines mapping between main table and foreign table GridRelationDescriptor rd = new GridRelationDescriptor(); rd.Name = "CustomerColDisplay"; //just some unique name rd.RelationKind = RelationKind.ForeignKeyReference; //foreign key look up rd.ChildTableName = lookUpDataTable.TableName; // SourceListSet name for lookup //get foreign key for col "CustomerID" in foreign table rd.RelationKeys.Add("Customer", "CustomerID"); //col in main table, foreign key col //Set any optional properties on the relation // dropdown only shows CustomerName rd.ChildTableDescriptor.VisibleColumns.Add("CustomerName"); //display column rd.ChildTableDescriptor.SortedColumns.Add("CustomerName"); //sort it for dropdown display rd.ChildTableDescriptor.AllowEdit = false; //no editing of foreign table rd.ChildTableDescriptor.AllowNew = false; //no new items added to foreign table rd.ChildTableDescriptor.Appearance.AlternateRecordFieldCell.BackColor = Color.FromArgb(0xff, 0xbf, 0x34); //add relation descriptor to main tabledescriptor td.Relations.Add(rd); //Add the relation column to main TableDescriptor's Columns collection. this.gridGroupingControl1.TableDescriptor.Columns.Add("Customer"); //Replace maintable.LookUpCol with foreigntable.DisplayCol string foreignPrefix = rd.Name + "_"; //get the hashed name of foreign col string foreignDisplayColInMainTable = foreignPrefix + "CustomerName"; td.VisibleColumns.Insert(lookUpIndex, foreignDisplayColInMainTable); //set its headertext to something other than default hashedname td.Columns[foreignDisplayColInMainTable].HeaderText = "Customer"; td.Columns[foreignDisplayColInMainTable].Appearance.AnyCell.BackColor = Color.FromArgb(218, 229, 245); foreach (GridColumnDescriptor col in this.gridGroupingControl1.TableDescriptor.Columns) { int index = (new Regex(@"\p{Lu}")).Match(col.MappingName.Substring(1)).Index; if (index > -1) { col.HeaderText = col.MappingName.Substring(0, index + 1) + " " + col.MappingName.Substring(index + 1); } } }
/// <summary> /// Group the GridGroingControl by Rating column /// </summary> void SetupGroupByRatings() { // // In this method we swap the Products and Ratings table. At startup the // DataSource is set to the Products table which has a parent child relation // with Ratings. // // In this method we assign the Ratings table as main DataSource and add // a ForeignKey relation to the products table. This allows products that // have multiple ratings to appear more than once. // // The foreign key relation from Products to Suppliers will be saved // and reapplied in this method. // GridTableDescriptor mainTd = this.gridGroupingControl1.TableDescriptor; this.gridGroupingControl1.Table.CurrentElement = null; // Reset all Grouping mainTd.GroupedColumns.Clear(); mainTd.VisibleColumns.Reset(); // Save the relations we previously defined for Ratings copyOfProducsRatings = new GridRelationDescriptor(); copyOfProducsRatings.InitializeFrom(mainTd.Relations["Ratings"]); // Save also Suppliers and RatingDescription so that they can be reapplied. GridRelationDescriptor suppliersRd = new GridRelationDescriptor(); suppliersRd.InitializeFrom(mainTd.Relations["Suppliers"]); GridRelationDescriptor ratingsDescriptionRd = new GridRelationDescriptor(); ratingsDescriptionRd.InitializeFrom(copyOfProducsRatings.ChildTableDescriptor.Relations["RatingDescription"]); // // Change MappingNames for Columns. The name of the column stays the same. // foreach (GridColumnDescriptor cd in mainTd.Columns) { if (cd.MappingName.StartsWith("Ratings_")) { cd.MappingName = cd.MappingName.Substring("Ratings_".Length); } else { cd.MappingName = "Products_" + cd.MappingName; } } // // Set up foreign key relation from Ratings to Products // so that each Product can now appear multiple times, once for each Rating it has. // GridRelationDescriptor productsRd = new GridRelationDescriptor(); productsRd.RelationKind = RelationKind.ForeignKeyReference; productsRd.ChildTableName = "Products"; productsRd.RelationKeys.Add("ProductID", "ProductID"); productsRd.ChildTableDescriptor.Relations.Clear(); // // Main DataSource is now "Ratings" table. Add foreign key relations to products and // restore the Suppliers and RatingDescription relation. // mainTd.Relations.Clear(); mainTd.Relations.Add(productsRd); mainTd.Relations.Add(ratingsDescriptionRd); productsRd.ChildTableDescriptor.Relations.Add(suppliersRd); mainTd.Name = "Group by Ratings"; this.gridGroupingControl1.DataSource = this.productRatingsDataSet2.Ratings; }
private void CargaGrid(String NDoc) { DataSet DSDevuelve = new DataSet(); DataTable DTMain = new DataTable(); DataView DVMain = new DataView(); DataTable DTTipo = new DataTable(); DataView DVTipo = new DataView(); DataTable DTNivel = new DataTable(); DataView DVNivel = new DataView(); GGCVista.DataSource = null; GGCVista.TableDescriptor.Reset(); GGCVista.TableDescriptor.AllowNew = false; GGCVista.Refresh(); WSComunes.WSComunes WSComun = new WSComunes.WSComunes(); WSComun.Url = mdlGenerales.DireccionWS + "FazServices/WSComunes.asmx"; DSDevuelve = WSComun.DevuelveStoreUnaVariable(mdlGenerales.Conexion, "sp_devuelve_usuario_rol", NDoc); DTMain = DSDevuelve.Tables[0]; DVMain = DTMain.DefaultView; DTTipo = DSDevuelve.Tables[1]; DVTipo = DTTipo.DefaultView; DTNivel = DSDevuelve.Tables[2]; DVNivel = DTNivel.DefaultView; GGCVista.TopLevelGroupOptions.ShowFilterBar = false; GGCVista.TopLevelGroupOptions.ShowAddNewRecordBeforeDetails = false; GGCVista.TopLevelGroupOptions.ShowAddNewRecordAfterDetails = false; //Limpia Grilla GGCVista.DataSource = null; GGCVista.DataMember = null; GGCVista.ResetTableDescriptor(); GGCVista.TableDescriptor.Relations.Clear(); GridTableDescriptor mainTD = GGCVista.TableDescriptor; /*Relacion Foreign y llenado de combo ojo*/ GGCVista.Engine.SourceListSet.Add("TipoRelacion", DTTipo); GridRelationDescriptor CargosRd = new GridRelationDescriptor(); CargosRd.Name = "Tipo"; CargosRd.RelationKind = RelationKind.ForeignKeyReference; CargosRd.ChildTableName = "TipoRelacion"; // SourceListSet name for lookup CargosRd.RelationKeys.Add("IDTipo", "IDTipo"); CargosRd.ChildTableDescriptor.Appearance.AlternateRecordFieldCell.BackColor = Color.CadetBlue; CargosRd.ChildTableDescriptor.AllowEdit = false; CargosRd.ChildTableDescriptor.AllowNew = false; mainTD.Relations.Add(CargosRd); /*Relacion Foreign y llenado de combo ojo*/ GGCVista.Engine.SourceListSet.Add("NivelRelacion", DTNivel); GridRelationDescriptor EstadoRd = new GridRelationDescriptor(); EstadoRd.Name = "Nivel"; EstadoRd.RelationKind = RelationKind.ForeignKeyReference; EstadoRd.ChildTableName = "NivelRelacion"; // SourceListSet name for lookup EstadoRd.RelationKeys.Add("IDNivel", "IDNivel"); EstadoRd.ChildTableDescriptor.Appearance.AlternateRecordFieldCell.BackColor = Color.CadetBlue; EstadoRd.ChildTableDescriptor.AllowEdit = false; EstadoRd.ChildTableDescriptor.AllowNew = false; mainTD.Relations.Add(EstadoRd); GGCVista.DataSource = DTMain; FormatColumnas(); AplicarFilterBar(); }