protected override NWidget CreateExampleContent() { m_GridView = new NTableGridView(); m_GridView.Grid.DataSource = NDummyDataSource.CreatePersonsOrdersDataSource(); // create a total column that is pinned to the right // add an event calculated column of type Double NCustomCalculatedColumn <Double> totalColumn = new NCustomCalculatedColumn <Double>(); totalColumn.Title = "Total"; totalColumn.FreezeMode = ENColumnFreezeMode.Right; totalColumn.GetRowValueDelegate += delegate(NCustomCalculatedColumnGetRowValueArgs <double> arg) { // calculate a RowValue for the RowIndex double price = Convert.ToDouble(arg.DataSource.GetValue(arg.RowIndex, "Price")); double quantity = Convert.ToDouble(arg.DataSource.GetValue(arg.RowIndex, "Quantity")); return((double)(price * quantity)); }; totalColumn.Format.BackgroundFill = new NColorFill(NColor.SeaShell); m_GridView.Grid.Columns.Add(totalColumn); // freeze the pruduct name to the left NColumn productNameColumn = m_GridView.Grid.Columns.GetColumnByFieldName("Product Name"); productNameColumn.Format.BackgroundFill = new NColorFill(NColor.SeaShell); productNameColumn.FreezeMode = ENColumnFreezeMode.Left; return(m_GridView); }
protected override NWidget CreateExampleContent() { NTableGridView view = new NTableGridView(); NTableGrid grid = view.Grid; // bind the grid to the data source, but exclude the "PersonId" column. grid.AutoCreateColumn += delegate(NAutoCreateColumnEventArgs arg) { if (arg.FieldInfo.Name == "PersonId") { arg.DataColumn = null; } }; grid.DataSource = NDummyDataSource.CreatePersonsOrdersDataSource(); // add a custom calculated column of type Double that displays the Total (e.g. Price * Quantity) NCustomCalculatedColumn <double> totalColumn = new NCustomCalculatedColumn <double>(); totalColumn.Title = "Total"; totalColumn.GetRowValueDelegate += delegate(NCustomCalculatedColumnGetRowValueArgs <double> arg) { // calculate a RowValue for the RowIndex double price = Convert.ToDouble(arg.DataSource.GetValue(arg.RowIndex, "Price")); double quantity = Convert.ToDouble(arg.DataSource.GetValue(arg.RowIndex, "Quantity")); return((double)(price * quantity)); }; totalColumn.Format.BackgroundFill = new NColorFill(NColor.SeaShell); grid.Columns.Add(totalColumn); // show only records where PersonId = "0" // NOTE: when the rule is not associated with a column, you must explicitly specify a row value for the row condition. NFilteringRule personIdFilterRule = new NFilteringRule(); NOperatorRowCondition rowCondition = new NOperatorRowCondition(ENRowConditionOperator.Equals, "0"); rowCondition.RowValue = new NFieldRowValue("PersonId"); personIdFilterRule.RowCondition = rowCondition; grid.FilteringRules.Add(personIdFilterRule); // show only records for which the total column is larger than 150 // NOTE: when the rule is associated with a column, by default the row condition operates on the column values. NFilteringRule companyFilterRule = new NFilteringRule(); companyFilterRule.Column = totalColumn; companyFilterRule.RowCondition = new NOperatorRowCondition(ENRowConditionOperator.GreaterThan, "150"); grid.FilteringRules.Add(companyFilterRule); // customize the grid grid.AllowSortColumns = true; grid.AlternatingRows = true; grid.RowHeaders.Visible = true; return(view); }
protected override NWidget CreateExampleContent() { // create a view and get its grid NTableGridView view = new NTableGridView(); NTableGrid grid = view.Grid; // bind the grid to the data source grid.DataSource = NDummyDataSource.CreatePersonsOrdersDataSource(); // add a custom calculated column of type Double that displays the Total (e.g. Price * Quantity) NCustomCalculatedColumn <double> totalColumn = new NCustomCalculatedColumn <double>(); totalColumn.Title = "Total"; totalColumn.GetRowValueDelegate += delegate(NCustomCalculatedColumnGetRowValueArgs <double> arg) { // calculate a RowValue for the RowIndex double price = Convert.ToDouble(arg.DataSource.GetValue(arg.RowIndex, "Price")); double quantity = Convert.ToDouble(arg.DataSource.GetValue(arg.RowIndex, "Quantity")); return((double)(price * quantity)); }; totalColumn.Format.BackgroundFill = new NColorFill(NColor.SeaShell); grid.Columns.Add(totalColumn); // create the sales sorting rule. // also subcribe for the create sorting rule event to recreate the rule when users grid.SortingRules.Add(CreateTotalSortingRule(grid)); totalColumn.CreateSortingRuleDelegate = delegate(NColumn theColumn) { return(CreateTotalSortingRule(grid)); }; // alter some view preferences grid.AllowSortColumns = true; grid.AlternatingRows = true; grid.RowHeaders.Visible = true; return(view); }
protected override NWidget CreateExampleContent() { m_GridView = new NTableGridView(); NTableGrid grid = m_GridView.Grid; // bind the grid to the data source grid.DataSource = NDummyDataSource.CreatePersonsOrdersDataSource(); // add an event calculated column of type Double NCustomCalculatedColumn <Double> totalColumn = new NCustomCalculatedColumn <Double>(); totalColumn.Title = "Total"; totalColumn.GetRowValueDelegate += delegate(NCustomCalculatedColumnGetRowValueArgs <double> arg) { // calculate a RowValue for the RowIndex double price = Convert.ToDouble(arg.DataSource.GetValue(arg.RowIndex, "Price")); double quantity = Convert.ToDouble(arg.DataSource.GetValue(arg.RowIndex, "Quantity")); return((double)(price * quantity)); }; totalColumn.Format.BackgroundFill = new NColorFill(NColor.SeaShell); grid.Columns.Add(totalColumn); return(m_GridView); }
protected override NWidget CreateExampleContent() { // create a view and get its grid NTableGridView view = new NTableGridView(); NTableGrid grid = view.Grid; // customize the grid grid.AllowEdit = false; // bind to data source, but exclude the "PersonId" field from binding grid.AutoCreateColumn += delegate(NAutoCreateColumnEventArgs arg) { if (arg.FieldInfo.Name == "PersonId") { arg.DataColumn = null; } }; grid.DataSource = NDummyDataSource.CreatePersonsOrdersDataSource(); // create a calculated Total column NCustomCalculatedColumn <double> totalColumn = new NCustomCalculatedColumn <double>(); totalColumn.Title = "Total"; totalColumn.GetRowValueDelegate = delegate(NCustomCalculatedColumnGetRowValueArgs <double> args) { double price = Convert.ToDouble(args.DataSource.GetValue(args.RowIndex, "Price")); int quantity = Convert.ToInt32(args.DataSource.GetValue(args.RowIndex, "Quantity")); return((double)(price * quantity)); }; grid.Columns.Add(totalColumn); // create a grouping rule that groups by the Product Name column NGroupingRule groupingRule = new NGroupingRule(grid.Columns.GetColumnByFieldName("Product Name")); // create a footer summary row for the total total groupingRule.CreateFooterSummaryRowsDelegate = delegate(NGroupingRuleCreateSummaryRowsArgs args) { // get the recordset for the group NRecordset recordset = args.GroupRow.Recordset; // calculate the sum of totals double total = 0; for (int i = 0; i < recordset.Count; i++) { total += Convert.ToDouble(totalColumn.GetRowValue(recordset[i])); } // create the total summary row NSummaryRow totalRow = new NSummaryRow(); totalRow.Cells = new NSummaryCellCollection(); NSummaryCell cell = new NSummaryCell(); cell.BeginXPosition.Mode = ENSpanCellBeginXPositionMode.AnchorToEndX; cell.EndXPosition.Mode = ENSpanCellEndXPositionMode.RowEndX; cell.Content = new NLabel("Grand Total: " + total.ToString("0.00")); totalRow.Cells.Add(cell); return(new NSummaryRow[] { totalRow }); }; grid.GroupingRules.Add(groupingRule); return(view); }