Ejemplo n.º 1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            DataTable custTable = new DataTable("Customers");

            // add columns
            custTable.Columns.Add("id", typeof(int));
            custTable.Columns.Add("name", typeof(string));
            custTable.Columns.Add("address", typeof(string));
            custTable.Columns.Add("min", typeof(int));
            custTable.Columns["min"].DefaultValue = 0;
            custTable.Columns.Add("max", typeof(int));

            // set PrimaryKey
            custTable.Columns["id"].Unique = true;
            custTable.PrimaryKey           = new DataColumn[] { custTable.Columns["id"] };

            custTable.ColumnChanging += new DataColumnChangeEventHandler(custTable_ColumnChanging);
            custTable.RowChanging    += new DataRowChangeEventHandler(custTable_RowChanging);


            Random rnd = new Random();

            // add ten rows
            for (int id = 1; id <= 10; id++)
            {
                int valMin = rnd.Next(0, 1000);

                custTable.Rows.Add(
                    new object[] { id, string.Format("customer{0}", id), string.Format("address{0}", id), valMin, valMin + rnd.Next(1, 1000) });
            }

            dataGrid.DataSource = custTable.DefaultView;

            dataGrid.AutoSizeCells();


            dataGrid.GridController.AddController(SourceGrid.Controllers.SelectionDrag.Copy);
            dataGrid.GridController.AddController(SourceGrid.Controllers.SelectionDrag.Copy);
            dataGrid.GridController.AddController(SourceGrid.Controllers.SelectionDrop.Default);
            dataGrid.GridController.AddController(SourceGrid.Controllers.SelectionDrop.Default);
            dataGrid.GridController.AddController(SourceGrid.Controllers.SelectionClipboard.CopyCut);
            dataGrid.GridController.AddController(SourceGrid.Controllers.SelectionClipboard.CopyCut);
        }
Ejemplo n.º 2
0
        private void frmSample41_Load(object sender, System.EventArgs e)
        {
            //Read Data From xml
            DataSet ds = new DataSet();

            System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsFormsSample.GridSamples.SampleData2.xml");
            ds.ReadXml(stream);
            mView             = ds.Tables[0].DefaultView;
            mView.AllowDelete = false;
            mView.AllowNew    = false;

            dataGrid.FixedColumns = 1;

            DevAge.ComponentModel.IBoundList bd = new DevAge.ComponentModel.BoundDataView(mView);

            //Create default columns
            CreateColumns(bd);

            dataGrid.DataSource = bd;

            dataGrid.AutoSizeCells();

            dataGrid.Selection.SelectionChanged += new SourceGrid.RangeRegionChangedEventHandler(Selection_SelectionChanged);
        }