Ejemplo n.º 1
0
        void Form1_Load(object sender, System.EventArgs e)
        {
            // fill data set with orders, details
            string           conn = GetConnectionString();
            OleDbDataAdapter da   = new OleDbDataAdapter("select * from orders", conn);

            da.Fill(ds, "Orders");
            da = new OleDbDataAdapter("select * from [order details]", conn);
            da.Fill(ds, "[Order Details]");

            // set up a relation between orders and details
            DataColumn parentColumn = ds.Tables["Orders"].Columns["OrderID"];
            DataColumn childColumn  = ds.Tables["[Order Details]"].Columns["OrderID"];

            ds.Relations.Add("Orders_Details", parentColumn, childColumn);

            // add a "Selected" column to the orders
            DataColumn selectionCol = new DataColumn("Selected", typeof(bool));

            selectionCol.DefaultValue = false;
            ds.Tables["Orders"].Columns.Add(selectionCol);

            // bind top grid to orders
            _flexMaster.SetDataBinding(ds, "Orders");
            _flexMaster.Cols[0].Width = 20;
            _flexDetail.Cols[0].Width = 20;

            // make "Selected" column the first one
            _flexMaster.Cols["Selected"].Move(1);

            // don't bind bottom grid, wait for selection to change
            // (this would the simple way to do master-detail)
            //_flexDetail.SetDataBinding(ds, "Orders.Orders_Details");
            //_flexDetail.SelectionMode = SelectionModeEnum.ListBox;

            // instead, bind the detail to an empty clone of the details
            // table and update the table when the user changes the selection
            dtDetails = ds.Tables["[Order Details]"].Clone();
            _flexDetail.DataSource = dtDetails;
        }