//public int CompareCategoryKey(SortColumnDescriptor column, bool isForeignKey, object category, Record record) //{ // throw new NotImplementedException(); //} #region IGroupByColumnCategorizer Members //public object GetGroupByCategoryKey(SortColumnDescriptor column, bool isForeignKey, Record record) //{ // if (column.FieldDescriptor.FieldPropertyType == typeof(DateTime)) // { // DateTime date = (DateTime)record.GetValue(column); // int i = date.Month; // return GetCategory(int.Parse(i.ToString())); // } // else // return GetCategory(int.Parse(record.GetValue(column).ToString())); //} public object GetGroupByCategoryKey(SortColumnDescriptor column, bool isForeignKey, Record record) { if (column.FieldDescriptor.FieldPropertyType == typeof(DateTime)) { DateTime date = (DateTime)record.GetValue(column); return(date.ToString("MMMM")); } else { return(int.Parse(record.GetValue(column).ToString())); } }
//public int CompareCategoryKey(SortColumnDescriptor column, bool isForeignKey, object category, Record record) //{ // if (column.FieldDescriptor.FieldPropertyType == typeof(DateTime)) // { // DateTime date = (DateTime)record.GetValue(column); // int i = date.Month; // return GetCategory(int.Parse(i.ToString())) - (int)category; // } // else // return GetCategory(int.Parse(record.GetValue(column).ToString())) - (int)category; //} public int CompareCategoryKey(SortColumnDescriptor column, bool isForeignKey, object category, Record record) { if (column.FieldDescriptor.FieldPropertyType == typeof(DateTime)) { DateTime date = (DateTime)record.GetValue(column); int i = date.Month; //To return the month name return(i - GetMonths(category.ToString())); } else { return(int.Parse(record.GetValue(column).ToString()) - (int)category); } }
/// <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; } }
public int CompareCategoryKey(SortColumnDescriptor column, bool isForeignKey, object category, Record record) { // Here the position of the record is used to determine it's key rather than any specific value in the record. return(GetCategory(record.GetSourceIndex()) - (int)category); }
private void GroupColumn(string str) { SortColumnDescriptor gs = new SortColumnDescriptor(); gs.Name = str; gridGroupingControl1.TableDescriptor.GroupedColumns.Clear(); gridGroupingControl1.TableDescriptor.GroupedColumns.Add(gs); }