Ejemplo n.º 1
0
        /// <summary>
        /// RelationKind ListItemReference relation for looking up values from a strong-typed collection.
        /// </summary>
        private void SampleCustomization()
        {
            USStatesCollection  usStates  = USStatesCollection.CreateDefaultCollection();
            CountriesCollection countries = CountriesCollection.CreateDefaultCollection();

            this.gridGroupingControl1.Engine.SourceListSet.Add("Countries", countries);
            this.gridGroupingControl1.Engine.SourceListSet.Add("USStates", usStates);

            #region DataTable
            DataTable table = new DataTable();
            table.Columns.Add("Id", typeof(string));
            table.Columns.Add("Country", typeof(Country));
            table.Columns.Add("State", typeof(USState));

            // and then add a few rows:
            for (int i = 0; i < 50; i++)
            {
                table.Rows.Add(table.NewRow());
                table.Rows[i][0] = i;
                table.Rows[i][1] = countries[i % 8];
                if (i % 8 == 0)
                {
                    table.Rows[i][2] = usStates[i / 8];
                }
            }

            #endregion

            GridTableDescriptor mainTd = this.gridGroupingControl1.TableDescriptor;

            //creating new relation descroptor.
            GridRelationDescriptor usStatesRd = new GridRelationDescriptor();
            usStatesRd.Name           = "State";
            usStatesRd.MappingName    = "State";    // FieldName in table
            usStatesRd.ChildTableName = "USStates"; // SourceListSet name for lookup
            //setting Relation Kind as ListItemreference.
            usStatesRd.RelationKind = RelationKind.ListItemReference;
            usStatesRd.ChildTableDescriptor.Appearance.AlternateRecordFieldCell.BackColor = Color.FromArgb(255, 245, 227);
            usStatesRd.ChildTableDescriptor.VisibleColumns.Add("Name");
            usStatesRd.ChildTableDescriptor.SortedColumns.Add("Name");
            mainTd.Relations.Add(usStatesRd);

            GridRelationDescriptor countriesRd = new GridRelationDescriptor();
            countriesRd.Name           = "Country";
            countriesRd.MappingName    = "Country";   // FieldName in table
            countriesRd.ChildTableName = "Countries"; // SourceListSet name for lookup
            //setting Relation Kind as ListItemreference.
            countriesRd.RelationKind = RelationKind.ListItemReference;
            countriesRd.ChildTableDescriptor.Appearance.AlternateRecordFieldCell.BackColor = Color.FromArgb(255, 245, 227);
            countriesRd.ChildTableDescriptor.AllowEdit = true;
            countriesRd.ChildTableDescriptor.AllowNew  = true; // Make pencil icon appear, allow user to add countries (these setting will be overriden by CountriesCollection.IsReadOnly / CountriesCollection.IsFixedSize properties if they are true).
            mainTd.Relations.Add(countriesRd);


            //assigning datasource to the GridGroupingControl.
            this.gridGroupingControl1.DataSource = table;
        }
Ejemplo n.º 2
0
        public Class1()
        {
            engine1 = new Engine();

            USStatesCollection  usStates  = USStatesCollection.CreateDefaultCollection();
            CountriesCollection countries = CountriesCollection.CreateDefaultCollection();

            this.engine1.SourceListSet.Add("Countries", countries);
            this.engine1.SourceListSet.Add("USStates", usStates);

            DataTable table = new DataTable();

            table.Columns.Add("Id", typeof(string));
            table.Columns.Add("Country", typeof(Country));
            table.Columns.Add("State", typeof(USState));

            // and then add a few rows:
            for (int i = 0; i < 50; i++)
            {
                table.Rows.Add(table.NewRow());
                table.Rows[i][0] = i;
                table.Rows[i][1] = countries[i % 8];
                if (i % 8 == 0)
                {
                    table.Rows[i][2] = usStates[i / 8];
                }
            }

            TableDescriptor mainTd = this.engine1.TableDescriptor;
            //mainTd.Fields.ExpandProperties = false;

            RelationDescriptor usStatesRd = new RelationDescriptor();

            usStatesRd.Name           = "State";
            usStatesRd.MappingName    = "State";           // FieldName in table
            usStatesRd.ChildTableName = "USStates";        // SourceListSet name for lookup
            usStatesRd.RelationKind   = RelationKind.ListItemReference;
            usStatesRd.ChildTableDescriptor.SortedColumns.Add("Name");
            //usStatesRd.ChildTableDescriptor.AllowEdit = false;
            //usStatesRd.ChildTableDescriptor.AllowNew = false;  // users can't modify states.
            mainTd.Relations.Add(usStatesRd);

            RelationDescriptor countriesRd = new RelationDescriptor();

            countriesRd.Name           = "Country";
            countriesRd.MappingName    = "Country";           // FieldName in table
            countriesRd.ChildTableName = "Countries";         // SourceListSet name for lookup
            countriesRd.RelationKind   = RelationKind.ListItemReference;
            countriesRd.ChildTableDescriptor.AllowEdit = true;
            countriesRd.ChildTableDescriptor.AllowNew  = true;             // allow user to add countries (these setting will be overriden by CountriesCollection.IsReadOnly / CountriesCollection.IsFixedSize properties if they are true).
            mainTd.Relations.Add(countriesRd);
            this.engine1.SetSourceList(table.DefaultView);
        }