Пример #1
0
        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;

            // create the dummy persons data source - we will use it to obtain person names from person ids from it.
            m_PersonsDataSource = NDummyDataSource.CreatePersonsDataSource();

            // 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 grouping rule that groups by the PersonId field
            NGroupingRule groupingRule = new NGroupingRule();

            groupingRule.RowValue = new NFieldRowValue("PersonId");

            // create a custom grouping header named "Person"
            groupingRule.CreateGroupingHeaderContentDelegate = delegate(NGroupingRule theGroupingRule)
            {
                return(new NLabel("Person"));
            };

            // create custom group row cells that display the person Name and number of orders
            groupingRule.CreateGroupRowCellsDelegate = delegate(NGroupingRuleCreateGroupRowCellsArgs arg)
            {
                // get the person id from the row for which we create row cells.
                int personId = (int)arg.GroupRow.GroupValue;

                // get the person name that corresponds to that person id.
                int        idField    = m_PersonsDataSource.GetFieldIndex("Id");
                NRecordset rs         = m_PersonsDataSource.GetOrCreateIndex(idField).GetRecordsForValue(personId);
                string     personName = (string)m_PersonsDataSource.GetValue(rs[0], "Name");

                // create the group row cells
                NGroupRowCell personNameCell = new NGroupRowCell(personName);
                personNameCell.EndXPosition.Mode = ENSpanCellEndXPositionMode.NextCellBeginX;

                NGroupRowCell ordersCountCell = new NGroupRowCell("Orders Count:" + arg.GroupRow.Recordset.Count);
                ordersCountCell.EndXPosition.Mode   = ENSpanCellEndXPositionMode.RowEndX;
                ordersCountCell.BeginXPosition.Mode = ENSpanCellBeginXPositionMode.AnchorToEndX;

                return(new NGroupRowCell[] { personNameCell, ordersCountCell });
            };
            grid.GroupingRules.Add(groupingRule);

            return(view);
        }
Пример #2
0
        protected override NWidget CreateExampleContent()
        {
            // store current date time
            m_Now = DateTime.Now;

            // create a view and get its grid
            NTableGridView view = new NTableGridView();
            NTableGrid     grid = view.Grid;

            // bind the grid to the data source
            grid.DataSource = CreateMailDataSource();

            // create a grouping rule with a custom row value.
            // NOTE: The RowValue associated with each grouping rule, returns an object for each row of the data source.
            // the rows in the data source are grouped according to that object.
            // The NCustomRowValue provides a delegate that help you return a custom object object for each data source row.
            // In our example the NCustomRowValue returns a member of the ENMailGroup enumeraiton for each record, depending on its Received row value.
            NCustomRowValue <ENMailGroup> customRowValue = new NCustomRowValue <ENMailGroup>();

            customRowValue.Description         = "Received";
            customRowValue.GetRowValueDelegate = GetRowValueDelegate;

            // NOTE: The NGroupingRule provides the following events:
            // CreateGroupRowCells - raised when the grid needs to create the cells of the group row.
            // CreateGroupingHeaderContent - raised when the grid needs to create a grouping header content for the grouping in the groupings panel.
            NGroupingRule groupingRule = new NGroupingRule();

            groupingRule.RowValue = customRowValue;
            groupingRule.CreateGroupRowCellsDelegate = delegate(NGroupingRuleCreateGroupRowCellsArgs arg)
            {
                int    groupValue = Convert.ToInt32(arg.GroupRow.GroupValue);
                string text       = NStringHelpers.InsertSpacesBeforeUppersAndDigits(((ENMailGroup)groupValue).ToString());
                return(new NGroupRowCell[] { new NGroupRowCell(text) });
            };

            groupingRule.CreateGroupingHeaderContentDelegate = delegate(NGroupingRule theGroupingRule)
            {
                return(new NLabel("Received"));
            };

            grid.GroupingRules.Add(groupingRule);

            return(view);
        }
        protected override NWidget CreateExampleContent()
        {
            NTableGridView gridView = new NTableGridView();
            NTableGrid     grid     = gridView.Grid;

            // bind the grid to the data source
            grid.DataSource = NDummyDataSource.CreateCompanySalesDataSource();

            // create a grouping rule that groups by the company field value first
            // note that in order to indicate the grouping in the grouping panel, the rule must reference the respective column
            NColumn          companyColumn = grid.Columns.GetColumnByFieldName("Company");
            string           fx1           = grid.CreateFormulaFieldName("Company");
            NFormulaRowValue fxRowValue    = new NFormulaRowValue(fx1);
            NGroupingRule    groupingRule1 = new NGroupingRule(companyColumn, fxRowValue, ENSortingDirection.Ascending);

            grid.GroupingRules.Add(groupingRule1);

            // create a grouping rule that groups by sales larger than 1000 next
            // note that in order to indicate the grouping in the grouping panel, the rule must reference the respective column
            string        fx2           = grid.CreateFormulaFieldName("Sales") + ">1000";
            NColumn       salesColumn   = grid.Columns.GetColumnByFieldName("Sales");
            NGroupingRule groupingRule2 = NGroupingRule.FromFormula(salesColumn, fx2);

            groupingRule2.CreateGroupRowCellsDelegate += delegate(NGroupingRuleCreateGroupRowCellsArgs arg)
            {
                bool   groupValue = (bool)((NVariant)arg.GroupRow.GroupValue);
                string text       = groupValue? "Sales greater than 1000" : "Sales less than or equal to 1000";
                return(new NGroupRowCell[] { new NGroupRowCell(text) });
            };
            grid.GroupingRules.Add(groupingRule2);

            // alter some view preferences
            grid.AllowSortColumns   = true;
            grid.AlternatingRows    = true;
            grid.RowHeaders.Visible = true;

            return(gridView);
        }
Пример #4
0
        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);
        }