Exemplo n.º 1
0
        private void FillDataSet()
        {
            DataTable  users = dsSource.Tables.Add("Users");
            DataTable  zipcodes = dsSource.Tables.Add("ZipCodes");
            DataTable  countries = dsSource.Tables.Add("Countries");
            DataColumn users_id, zip_zipid, col;

            // Countries
            col         = countries.Columns.Add("name", Type.GetType("System.String"));
            col.Caption = "Available Countries";

            // Zipcodes
            zip_zipid = zipcodes.Columns.Add("zipID", Type.GetType("System.Int32"));
            zip_zipid.AutoIncrement = true;
            zipcodes.Columns.Add("area", Type.GetType("System.String"));
            zipcodes.Columns.Add("zipcode", Type.GetType("System.String"));
            zipcodes.PrimaryKey = new DataColumn [] { zip_zipid };

            // Users
            users_id = users.Columns.Add("userID", Type.GetType("System.Int32"));
            users_id.AutoIncrement = true;
            users.Columns.Add("name", Type.GetType("System.String"));
            users.Columns.Add("address", Type.GetType("System.String"));
            users.Columns.Add("zipcode", Type.GetType("System.Int32"));
            users.Columns.Add("useaddress", Type.GetType("System.Boolean"));

            users.PrimaryKey = new DataColumn [] { users_id };


            DataRelation rel = new DataRelation("relation",
                                                new DataColumn [] { zipcodes.Columns["zipID"] }, // parent
                                                new DataColumn [] { users.Columns["zipcode"] }); // child, consumer

            dsSource.Relations.Add(rel);

            // Zip codes
            DataRow tempRow = zipcodes.NewRow();

            tempRow["area"]    = "Eixample";
            tempRow["zipcode"] = "08039";
            zipcodes.Rows.Add(tempRow);

            tempRow            = zipcodes.NewRow();
            tempRow["area"]    = "Clot";
            tempRow["zipcode"] = "08026";
            zipcodes.Rows.Add(tempRow);

            // Users
            tempRow               = users.NewRow();
            tempRow["name"]       = "Joan";
            tempRow["address"]    = "Balmes 152";
            tempRow["zipcode"]    = "1";
            tempRow["useaddress"] = true;
            users.Rows.Add(tempRow);

            tempRow               = users.NewRow();
            tempRow["name"]       = "Pere";
            tempRow["address"]    = "Provenca 55";
            tempRow["zipcode"]    = "1";
            tempRow["useaddress"] = false;
            users.Rows.Add(tempRow);

            tempRow               = users.NewRow();
            tempRow["name"]       = "Jordi";
            tempRow["address"]    = "Londres 16";
            tempRow["zipcode"]    = "1";
            tempRow["useaddress"] = false;
            users.Rows.Add(tempRow);

            tempRow               = users.NewRow();
            tempRow["name"]       = "Marta";
            tempRow["address"]    = "Padilla 210";
            tempRow["zipcode"]    = "0";
            tempRow["useaddress"] = false;
            users.Rows.Add(tempRow);

            // Countries
            tempRow         = countries.NewRow();
            tempRow["name"] = "France";
            countries.Rows.Add(tempRow);

            tempRow         = countries.NewRow();
            tempRow["name"] = "Spain";
            countries.Rows.Add(tempRow);

            tempRow         = countries.NewRow();
            tempRow["name"] = "Italy";
            countries.Rows.Add(tempRow);
            dataGrid.DataSource = dsSource;
            dataGrid.DataMember = "Users";

            dataGrid.GetListManager().ItemChanged     += list_manager_item_changed;
            dataGrid.GetListManager().MetaDataChanged += list_manager_metadata_changed;
            dataGrid.GetListManager().PositionChanged += list_manager_position_changed;
            dataGrid.GetListManager().CurrentChanged  += list_manager_current_changed;

            users.RowChanging    += users_RowChanging;
            users.RowChanged     += users_RowChanged;
            users.ColumnChanging += users_ColumnChanging;
            users.ColumnChanged  += users_ColumnChanged;
        }