コード例 #1
0
        public Form1()
        {
            InitializeComponent();
            MySpreadsheet = new MySpreadsheet(50, 26);
            MySpreadsheet.CellPropertyChanged += new PropertyChangedEventHandler(SpreadSheetPropertyChanged);
            //Move the following into data-grid initialization
            //Populates the data grid with columns 'A' through 'Z'
            for (char col = 'A'; col <= 'Z'; ++col)
            {
                dataGridView1.Columns.Add("Column" + col, col.ToString());
            }
            //Creates 50 rows in the datagridview and numbers each row
            dataGridView1.Rows.Add(50);
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                row.HeaderCell.Value = (row.Index + 1).ToString();
            }

            //Fires when an event occurs which requires updating the UI cells, hacky use of PropertyChangedEventArgs parameter
            //used to pass the row and column of the cell which needs to be updated
            void SpreadSheetPropertyChanged(object sender, PropertyChangedEventArgs e)
            {
                AbstractCell cell   = (AbstractCell)sender;
                int          row    = cell.RowIndex;
                int          column = cell.ColumnIndex;

                dataGridView1[column, row].Value = MySpreadsheet.getCell(row, column).EvaluatedValue;
            }
        }
コード例 #2
0
        //Demo button generates cell content in 50 random cells along with demonstrating relational integrity in first two columns
        private void button2_Click_1(object sender, EventArgs e)
        {
            Random rndNumber = new Random();

            for (int count = 0; count < 50; count++)
            {
                int row = rndNumber.Next(0, 50);
                int col = rndNumber.Next(0, 26);
                MySpreadsheet.getCell(row, col).TextValue = "Not another random cell";
            }
            //for (int row = 0; row < MySpreadsheet.RowCount; row++)
            //{
            //    MySpreadsheet.getCell(row, 1).TextValue = "This is cell B" + (row + 1);
            //    MySpreadsheet.getCell(row, 0).TextValue = "=B" + (row + 1); //Used to demonstrate cells can respond appropriately to having value set to content of another cell
            //    //i.e. ex. B1_cell.value = "=B2" should evaluate to the value of the b2 cell
            //}
        }