/// <summary> /// Constructor. Initializes a new instance of the DataModel class. /// </summary> public DataModel() { // Minimum requirement for Grouping Engine - DataSource should be a IList collection DataList.Add(new Data(DateTime.Now.ToOADate(), value));// This is needed - otherwise grouping does not work group.SetSourceList(DataList); ExpressionFieldDescriptor exp = new ExpressionFieldDescriptor(); exp.Expression = "[X] > " + DateTime.Now.AddMinutes(-5).ToOADate(); RecordFilterDescriptor rfd = new RecordFilterDescriptor(exp.Expression); group.TableDescriptor.RecordFilters.Add(rfd); }
protected void FilterData() { // Minimum requirement for Grouping Engine - DataSource should be a IList collection // Bind it to the model Engine group = new Engine(); group.SetSourceList(list); ExpressionFieldDescriptor exp = new ExpressionFieldDescriptor(); string Str = textBox1.Text.Trim(); double Num; bool isNum = double.TryParse(Str, out Num); if (isNum) { exp.Expression = "[Y] > " + this.textBox1.Text.ToString(); RecordFilterDescriptor rfd = new RecordFilterDescriptor(exp.Expression); group.TableDescriptor.RecordFilters.Add(rfd); System.Diagnostics.Trace.WriteLine("Filtered Record Count:" + group.Table.FilteredRecords.Count); System.Diagnostics.Trace.WriteLine("Values greater than 30:"); this.chartControl1.Series[0].Points.Clear(); int j = 0; foreach (Record rec in group.Table.FilteredRecords) { string b = rec.GetData().ToString(); System.Diagnostics.Trace.WriteLine(b); this.chartControl1.Series[0].Points.Add(j, Convert.ToDouble(b)); j++; } this.label2.Text = "Number of Filtered points: " + group.Table.FilteredRecords.Count.ToString(); } else { this.label2.Text = "Enter valid input to filter the chart data"; } }
/// <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; } }