예제 #1
0
        /// <summary>
        /// 建立固定儲存格的內容,包括:標題列、標題行。
        /// </summary>
        private void CreateFixedArea()
        {
            brGrid.FixedColumns = DualEditForm.FixedColumns;
            brGrid.FixedRows    = DualEditForm.FixedRows;

            brGrid[0, 0]            = new SourceGrid.Cells.Header();
            brGrid[0, 0].View       = m_HeaderView;
            brGrid[0, 0].Row.Height = 22;
            //brGrid[0, 0].Column.AutoSizeMode = SourceGrid.AutoSizeMode.EnableAutoSize;

            // column headers
            int cnt = 0;

            for (int col = FixedColumns; col < brGrid.ColumnsCount; col++)
            {
                cnt++;
                SourceGrid.Cells.ColumnHeader hdr = new SourceGrid.Cells.ColumnHeader(cnt.ToString());
                //hdr.EnableResize = false;
                brGrid[0, col]      = hdr;
                brGrid[0, col].View = m_HeaderView;
            }

            // row headers
            cnt = 1;
            for (int row = FixedRows; row < brGrid.RowsCount; row += 3)
            {
                SourceGrid.Cells.RowHeader hdr = new SourceGrid.Cells.RowHeader(cnt.ToString());
                brGrid[row, 0]      = hdr;
                brGrid[row, 0].View = m_HeaderView;
                hdr.RowSpan         = 3;                // 不可以在指定 hdr 物件之前設定 RowSpan, 否則會出錯!
                cnt++;
            }

            RefreshRowNumbers();
        }
예제 #2
0
        private void SetGrid()
        {
            grid1.Redim(74, 8);
            // grid1.FixedRows = 2;
            // grid1.FixedColumns = 1;

            for (int i = 0; i < colCaption.Length; i++)
            {
                grid1[rowIndex[i], colIndex[i]]            = new SourceGrid.Cells.Header(colCaption[i]);
                grid1[rowIndex[i], colIndex[i]].RowSpan    = rowSpan[i];
                grid1[rowIndex[i], colIndex[i]].ColumnSpan = colSpan[i];
                grid1[rowIndex[i], colIndex[i]].View       = GridView.HeaderView;
            }
            grid1.Rows[0].Height          = 25;
            grid1.Rows[1].Height          = 25;
            grid1.Columns[0].AutoSizeMode = SourceGrid.AutoSizeMode.None;

            for (int i = 0; i < 72; i++)
            {
                grid1[i + 2, 0] = new SourceGrid.Cells.RowHeader(i + 1);
                grid1[i + 2, 1] = new SourceGrid.Cells.Cell("", typeof(string));
                grid1[i + 2, 2] = new SourceGrid.Cells.Cell("", typeof(string));
                grid1[i + 2, 3] = new SourceGrid.Cells.Cell("", typeof(string));
                grid1[i + 2, 4] = new SourceGrid.Cells.Cell("", typeof(string));
                grid1[i + 2, 5] = new SourceGrid.Cells.Cell("", typeof(string));
                grid1[i + 2, 6] = new SourceGrid.Cells.Cell("", typeof(string));
                grid1[i + 2, 7] = new SourceGrid.Cells.Cell("", typeof(string));
            }

            grid1.AutoSizeCells();
            grid1.AutoStretchColumnsToFitWidth = true;
            grid1.Columns.StretchToFit();
        }
예제 #3
0
        private void frmSample17_Load(object sender, System.EventArgs e)
        {
            grid1.Redim(40, 40);
            grid1.FixedColumns = 1;
            grid1.FixedRows    = 1;

            grid1[0, 0] = new SourceGrid.Cells.Header(null);
            for (int c = 1; c < grid1.ColumnsCount; c++)
            {
                SourceGrid.Cells.ColumnHeader header = new SourceGrid.Cells.ColumnHeader("Header " + c.ToString());
                header.AutomaticSortEnabled = false;

                //header.ColumnSelectorEnabled = true;
                //header.ColumnFocusEnabled = true;

                grid1[0, c] = header;
            }

            Random rnd = new Random();

            for (int r = 1; r < grid1.RowsCount; r++)
            {
                grid1[r, 0] = new SourceGrid.Cells.RowHeader("Header " + r.ToString());
                for (int c = 1; c < grid1.ColumnsCount; c++)
                {
                    if (rnd.NextDouble() > 0.20)
                    {
                        grid1[r, c] = new SourceGrid.Cells.Cell(r * c, typeof(int));
                    }
                    else
                    {
                        grid1[r, c] = null;
                    }
                }
            }

            var selection = grid1.Selection as SelectionBase;

            cPickSelBackColor.SelectedColor = Color.FromArgb(selection.BackColor.R, selection.BackColor.G, selection.BackColor.B);
            cPckBorderColor.SelectedColor   = selection.Border.Top.Color;
            trackSelectionAlpha.Value       = (int)selection.BackColor.A;
            trackBorderWidth.Value          = (int)selection.Border.Top.Width;

            cPickFocusBackColor.SelectedColor = Color.FromArgb(selection.FocusBackColor.R, selection.FocusBackColor.G, selection.FocusBackColor.B);
            trackFocusBackColorTrans.Value    = selection.FocusBackColor.A;


            this.cPickSelBackColor.SelectedColorChanged   += new System.EventHandler(this.cPickSelBackColor_SelectedColorChanged);
            this.cPckBorderColor.SelectedColorChanged     += new System.EventHandler(this.cPckBorderColor_SelectedColorChanged);
            this.trackSelectionAlpha.ValueChanged         += new System.EventHandler(this.trackSelectionAlpha_ValueChanged);
            this.trackBorderWidth.ValueChanged            += new System.EventHandler(this.trackBorderWidth_ValueChanged);
            this.trackFocusBackColorTrans.ValueChanged    += new System.EventHandler(this.trackFocusBackColorTrans_ValueChanged);
            this.cPickFocusBackColor.SelectedColorChanged += new System.EventHandler(this.cPickFocusBackColor_SelectedColorChanged);

            cbDashStyle.Validator = new DevAge.ComponentModel.Validator.ValidatorTypeConverter(typeof(System.Drawing.Drawing2D.DashStyle));
            cbDashStyle.Value     = selection.Border.Top.DashStyle;
        }
예제 #4
0
        /// <summary>
        /// 在指定的列索引新增一列(實際上是三列)。
        /// </summary>
        /// <param name="row"></param>
        private void GridInsertRowAt(int row)
        {
            row = GetBrailleRowIndex(row);              // 確保列索引為點字列所在的索引。
            brGrid.Rows.InsertRange(row, 3);

            // 建立列標題儲存格。
            int rowNum = row / 3 + 1;

            SourceGrid.Cells.Header hdr = new SourceGrid.Cells.Header(rowNum.ToString());
            brGrid[row, 0]      = hdr;
            brGrid[row, 0].View = m_HeaderView;
            hdr.RowSpan         = 3;
        }
예제 #5
0
        private void btLoad_Click(object sender, System.EventArgs e)
        {
            grid.Redim(0, 0);
            //Visual properties shared between all the cells
            SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
            view.BackColor = Color.Snow;

            //Editor (IDataModel) shared between all the cells
            SourceGrid.Cells.Editors.TextBox editor = new
                                                      SourceGrid.Cells.Editors.TextBox(typeof(string));

            grid.Redim(int.Parse(txtRows.Text), int.Parse(txtCols.Text));

            if (chkAddHeaders.Checked && grid.RowsCount > 0 &&
                grid.ColumnsCount > 0)
            {
                grid.FixedRows    = 1;
                grid.FixedColumns = 1;

                for (int r = grid.FixedRows; r < grid.RowsCount; r++)
                {
                    grid[r, 0] = new SourceGrid.Cells.RowHeader(r);
                }
                for (int c = grid.FixedColumns; c < grid.ColumnsCount; c++)
                {
                    SourceGrid.Cells.ColumnHeader header = new
                                                           SourceGrid.Cells.ColumnHeader(c);
                    header.AutomaticSortEnabled = false;
                    grid[0, c] = header;
                }
                grid[0, 0] = new SourceGrid.Cells.Header();
            }
            else
            {
                grid.FixedRows    = 0;
                grid.FixedColumns = 0;
            }

            for (int r = grid.FixedRows; r < grid.RowsCount; r++)
            {
                for (int c = grid.FixedColumns; c < grid.ColumnsCount; c++)
                {
                    grid[r, c] = new SourceGrid.Cells.Cell(r.ToString() + "," +
                                                           c.ToString());
                    grid[r, c].Editor = editor;
                    grid[r, c].View   = view;
                }
            }
            grid.Selection.Focus(new SourceGrid.Position(0, 0), true);
        }
예제 #6
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            currencyFormat.TypeConverter = new DevAge.ComponentModel.Converter.CurrencyTypeConverter(typeof(double));
            currencyView.TextAlignment   = DevAge.Drawing.ContentAlignment.MiddleRight;
            dateFormat.TypeConverter     = new DevAge.ComponentModel.Converter.DateTimeTypeConverter("MMM yyyy");

            grid1.Redim(8, 21);
            grid1.FixedColumns = 1;
            grid1.FixedRows    = 1;

            grid1[0, 0] = new SourceGrid.Cells.Header();

            //row headers
            grid1[1, 0]         = new SourceGrid.Cells.RowHeader("Revenue");
            grid1[2, 0]         = new SourceGrid.Cells.RowHeader("Employees Cost");
            grid1[3, 0]         = new SourceGrid.Cells.RowHeader("Tax");
            grid1[4, 0]         = new SourceGrid.Cells.RowHeader("Totals");
            grid1[4, 0].RowSpan = 4;

            Random rnd = new Random();

            for (int i = 0; i < 20; i++)
            {
                AddDate(i + 1, DateTime.Now.AddMonths(i), 2000 * rnd.NextDouble(), 1000 * rnd.NextDouble(), 500 * rnd.NextDouble());
            }

            //Totals
            grid1[4, 1] = new CellTotal("Revenue: ");
            grid1[4, 2] = new CellTotal(mTotRevenue.ToString("C"));
            grid1[5, 1] = new CellTotal("Employees Cost: ");
            grid1[5, 2] = new CellTotal(mTotEmployeesCost.ToString("C"));
            grid1[6, 1] = new CellTotal("Tax: ");
            grid1[6, 2] = new CellTotal(mTotTax.ToString("C"));
            grid1[7, 1] = new CellTotal("Total:");
            grid1[7, 2] = new CellTotal((mTotRevenue - (mTotEmployeesCost + mTotTax)).ToString("C"));

            grid1.Columns[1].AutoSizeMode = SourceGrid.AutoSizeMode.None;
            grid1.Columns[1].Width        = 100;
            grid1.Columns[2].AutoSizeMode = SourceGrid.AutoSizeMode.None;
            grid1.Columns[2].Width        = 100;
            grid1.Rows[4].AutoSizeMode    = SourceGrid.AutoSizeMode.None;
            grid1.Rows[5].AutoSizeMode    = SourceGrid.AutoSizeMode.None;
            grid1.Rows[6].AutoSizeMode    = SourceGrid.AutoSizeMode.None;
            grid1.Rows[7].AutoSizeMode    = SourceGrid.AutoSizeMode.None;
            grid1.AutoSizeCells();
        }
예제 #7
0
        /// <summary>
        /// Occurs when loading this control.
        /// </summary>
        /// <param name="eventArgs">
        /// The <see cref="EventArgs"/>.
        /// </param>
        protected override void OnLoad(EventArgs eventArgs)
        {
            const int numberOfRows = 6;
            const int numberOfCols = 4;

            grid.Redim(numberOfRows, numberOfCols);
            grid.FixedRows     = 1;
            grid.FixedColumns  = 1;
            grid.SelectionMode = SourceGrid.GridSelectionMode.Row;
            grid.ToolTipText   = "Linked Controls";

            grid[0, 0] = new SourceGrid.Cells.Header(null);

            // Create column header
            for (int i = 0; i < numberOfCols; i++)
            {
                string label;

                switch (i)
                {
                case 1:
                    label = "Description";
                    break;

                case 2:
                    label = "Value";
                    break;

                case 3:
                    label = "Unit";
                    break;

                default:
                    label = null;
                    break;
                }

                var header = new SourceGrid.Cells.ColumnHeader(label)
                {
                    AutomaticSortEnabled = false
                };

                grid[0, i] = header;
            }

            // Create some entries
            SourceGrid.Cells.Views.Cell visualAspect = new SourceGrid.Cells.Views.Cell();

            for (int i = 1; i < numberOfRows; i++)
            {
                string  label;
                string  unit;
                Control usedControl;
                SourceGrid.Cells.Controllers.ToolTipText toolTipController =
                    new SourceGrid.Cells.Controllers.ToolTipText();

                toolTipController.IsBalloon = true;

                switch (i)
                {
                case 1:
                    label       = "Numeric Up Down [3...15]";
                    unit        = "µs";
                    usedControl = new NumericUpDown();
                    (usedControl as NumericUpDown).Minimum   = 3;
                    (usedControl as NumericUpDown).Maximum   = 15;
                    (usedControl as NumericUpDown).Increment = 2;
                    (usedControl as NumericUpDown).Value     = 7;
                    break;

                case 2:
                    label       = "Text box with max. length of 15 chars.";
                    unit        = ":o)";
                    usedControl = new TextBox();
                    (usedControl as TextBox).MaxLength = 15;
                    (usedControl as TextBox).Text      = "Some Text";
                    break;

                case 3:
                    label       = "Disabled text box";
                    unit        = "^_^";
                    usedControl = new TextBox();
                    (usedControl as TextBox).Enabled = false;
                    (usedControl as TextBox).Text    = "Some disabled Text";
                    break;

                case 4:
                    label       = "Combo box with auto complete";
                    unit        = "Prio.";
                    usedControl = new ComboBox();
                    (usedControl as ComboBox).Items.AddRange(
                        new object[] { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" });
                    (usedControl as ComboBox).AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
                    (usedControl as ComboBox).AutoCompleteSource = AutoCompleteSource.ListItems;
                    break;

                default:
                    label = "Progress bar";
                    unit  = "";
                    Random randNmbr = new Random();
                    usedControl = new ProgressBar();
                    (usedControl as ProgressBar).Value = randNmbr.Next(0, 100);
                    break;
                }

                grid[i, 1] = new SourceGrid.Cells.Cell
                {
                    View = visualAspect, Value = label, ToolTipText = label + "..." + unit
                };
                grid[i, 1].AddController(toolTipController);

                grid[i, 2] = new SourceGrid.Cells.Cell();

                usedControl.Enter += delegate(object sender, EventArgs e)
                {
                    IsRechangingSelection = true;

                    foreach (RowInfo rowInfo in grid.Rows)
                    {
                        grid.Selection.SelectRow(rowInfo.Index, false);
                    }

                    foreach (LinkedControlValue lcv in grid.LinkedControls)
                    {
                        if (lcv.Control == usedControl)
                        {
                            grid.Selection.SelectRow(lcv.Position.Row, true);
                            break;
                        }
                    }

                    IsRechangingSelection = false;
                };

                grid.LinkedControls.Add(new SourceGrid.LinkedControlValue(usedControl, new SourceGrid.Position(i, 2)));

                grid[i, 3] = new SourceGrid.Cells.Cell {
                    View = visualAspect, Value = unit
                };
            }

            if (grid.Columns[2].MinimalWidth < 127)
            {
                grid.Columns[2].MinimalWidth = 127;
            }

            grid.VScrollBar.ValueChanged += delegate(object sender, EventArgs valueChangedEventArgs)
            {
                // Hide all linked controls above 'new value'
                // Show all linked controls beyond 'new value'
                foreach (LinkedControlValue lcv in grid.LinkedControls)
                {
                    lcv.Control.Visible = lcv.Position.Row > grid.VScrollBar.Value;
                }

                // Reselecting works more or less when scrolling down. But what when scrolling up?
                if (grid.Selection.ActivePosition.Row <= grid.VScrollBar.Value)
                {
                    IsRechangingSelection = false;

                    foreach (LinkedControlValue lcv in grid.LinkedControls)
                    {
                        grid.Selection.SelectRow(lcv.Position.Row, false);
                    }

                    IsRechangingSelection = true;

                    grid.Selection.SelectRow(grid.VScrollBar.Value + 1, true);
                }
            };

            // Focus the custom control when changing selection
            grid.Selection.SelectionChanged += delegate(object sender, RangeRegionChangedEventArgs e)
            {
                if (!IsRechangingSelection && e.AddedRange != null && e.RemovedRange == null)
                {
                    bool  isFound      = false;
                    int   selectedRow  = -1;
                    int   selectedCol  = -1;
                    int[] selectedRows = e.AddedRange.GetRowsIndex();

                    if (sender is SourceGrid.Selection.SelectionBase)
                    {
                        selectedRow = (sender as SourceGrid.Selection.SelectionBase).ActivePosition.Row;
                        selectedCol = (sender as SourceGrid.Selection.SelectionBase).ActivePosition.Column;
                    }

                    if (selectedRows[0] != -1)
                    {
                        selectedRow = selectedRows[0];
                    }

                    foreach (LinkedControlValue lcv in grid.LinkedControls)
                    {
                        if (lcv.Position.Row == selectedRow)
                        {
                            // Remove focus from control
                            isFound = true;
                            lcv.Control.Focus();
                            break;
                        }
                    }

                    if (!isFound)
                    {
                        IsRechangingSelection = true;
                        grid.Selection.Focus(new Position(selectedRow, selectedCol), true);
                        IsRechangingSelection = false;
                    }
                }
            };
        }
예제 #8
0
		private void frmSample17_Load(object sender, System.EventArgs e)
		{
			grid1.Redim(40,40);
            grid1.FixedColumns = 1;
            grid1.FixedRows = 1;

			grid1[0,0] = new SourceGrid.Cells.Header(null);
			for (int c = 1; c < grid1.ColumnsCount; c++)
			{
				SourceGrid.Cells.ColumnHeader header = new SourceGrid.Cells.ColumnHeader("Header " + c.ToString());
                header.AutomaticSortEnabled = false;

                //header.ColumnSelectorEnabled = true;
                //header.ColumnFocusEnabled = true;

                grid1[0, c] = header;
			}

			Random rnd = new Random();
			for (int r = 1; r < grid1.RowsCount; r++)
			{
				grid1[r,0] = new SourceGrid.Cells.RowHeader("Header " + r.ToString());
				for (int c = 1; c < grid1.ColumnsCount; c++)
				{
					if (rnd.NextDouble() > 0.20)
					{
						grid1[r,c] = new SourceGrid.Cells.Cell(r*c, typeof(int));
					}
					else
						grid1[r,c] = null;
				}
			}

			cPickSelBackColor.SelectedColor = Color.FromArgb(grid1.Selection.BackColor.R, grid1.Selection.BackColor.G, grid1.Selection.BackColor.B);
			cPckBorderColor.SelectedColor = grid1.Selection.Border.Top.Color;
			trackSelectionAlpha.Value = (int)grid1.Selection.BackColor.A;
			trackBorderWidth.Value = (int)grid1.Selection.Border.Top.Width;

			cPickFocusBackColor.SelectedColor = Color.FromArgb(grid1.Selection.FocusBackColor.R, grid1.Selection.FocusBackColor.G, grid1.Selection.FocusBackColor.B);
			trackFocusBackColorTrans.Value = grid1.Selection.FocusBackColor.A;


			this.cPickSelBackColor.SelectedColorChanged += new System.EventHandler(this.cPickSelBackColor_SelectedColorChanged);
			this.cPckBorderColor.SelectedColorChanged += new System.EventHandler(this.cPckBorderColor_SelectedColorChanged);
			this.trackSelectionAlpha.ValueChanged += new System.EventHandler(this.trackSelectionAlpha_ValueChanged);
			this.trackBorderWidth.ValueChanged += new System.EventHandler(this.trackBorderWidth_ValueChanged);
			this.trackFocusBackColorTrans.ValueChanged += new System.EventHandler(this.trackFocusBackColorTrans_ValueChanged);
			this.cPickFocusBackColor.SelectedColorChanged += new System.EventHandler(this.cPickFocusBackColor_SelectedColorChanged);

			cbDashStyle.Validator = new DevAge.ComponentModel.Validator.ValidatorTypeConverter(typeof(System.Drawing.Drawing2D.DashStyle));
			cbDashStyle.Value = grid1.Selection.Border.Top.DashStyle;
		}
예제 #9
0
        private void SetGrid()
        {
            grid1.Redim(74,8);
            grid1.FixedRows = 2;
            grid1.FixedColumns = 1;

            for (int i = 0; i < colCaption.Length; i++)
            {
                grid1[rowIndex[i], colIndex[i]] = new SourceGrid.Cells.Header(colCaption[i]);
                grid1[rowIndex[i], colIndex[i]].RowSpan = rowSpan[i];
                grid1[rowIndex[i], colIndex[i]].ColumnSpan = colSpan[i];
                grid1[rowIndex[i], colIndex[i]].View = GridView.HeaderView;
            }
            grid1.Rows[0].Height = 25;
            grid1.Rows[1].Height = 25;
            grid1.Columns[0].AutoSizeMode = SourceGrid.AutoSizeMode.None;

            for (int i = 0; i < 72; i++)
            {
                grid1[i + 2, 0] = new SourceGrid.Cells.RowHeader(i+1);
                grid1[i + 2, 1] = new SourceGrid.Cells.Cell("", typeof(string));
                grid1[i + 2, 2] = new SourceGrid.Cells.Cell("", typeof(string));
                grid1[i + 2, 3] = new SourceGrid.Cells.Cell("", typeof(string));
                grid1[i + 2, 4] = new SourceGrid.Cells.Cell("", typeof(string));
                grid1[i + 2, 5] = new SourceGrid.Cells.Cell("", typeof(string));
                grid1[i + 2, 6] = new SourceGrid.Cells.Cell("", typeof(string));
                grid1[i + 2, 7] = new SourceGrid.Cells.Cell("", typeof(string));
            }

            grid1.AutoSizeCells();
            grid1.AutoStretchColumnsToFitWidth = true;
            grid1.Columns.StretchToFit();
        }
예제 #10
0
        protected virtual void BindToViewModel()
        {
            ClearSelection();
            if (ViewModel == null)
            {
                _grid.Redim(0, 0);
                return;
            }
            var dataSourceRowCount = ViewModel.GetRowCount();
            var dataSourceColCount = ViewModel.GetColumnCount();
            var colIndexOffset     = HasRowHeaders ? 2 : 0;
            var rowIndexOffset     = HasColHeaders ? 1 : 0;

            _grid.Redim(dataSourceRowCount + rowIndexOffset, dataSourceColCount + colIndexOffset);
            for (int i = 0; i < _grid.ColumnsCount; i++)
            {
                if (this.MaxColumnWidth > 0)
                {
                    _grid.Columns[i].MaximalWidth = this.MaxColumnWidth;
                }
                if (this.MinColumnWidth > 0)
                {
                    _grid.Columns[i].MinimalWidth = this.MinColumnWidth;
                }
                _grid.Columns[i].AutoSizeMode = SourceGrid.AutoSizeMode.EnableStretch;
            }
            var rowHeaders = (
                from rowNumber in Enumerable.Range(0, dataSourceRowCount)
                select ViewModel.GetRowHeaderText(rowNumber)
                ).ToLookup(x => x.Item1, x => x.Item2);

            if (HasRowHeaders)
            {
                for (int i = 0; i < _grid.RowsCount; i++)
                {
                    _grid[i, 0] = _grid[i, 1] = null;
                }

                _grid[0, 0]            = new SourceGrid.Cells.Header("Time");
                _grid[0, 0].ColumnSpan = 2;

                _grid.Columns[0].AutoSizeMode = SourceGrid.AutoSizeMode.None;
                _grid.Columns[0].MinimalWidth = 0;
                _grid.Columns[0].MaximalWidth = RowHeaderColumnWidth;
                _grid.Columns[0].Width        = RowHeaderColumnWidth;

                _grid.Columns[1].AutoSizeMode = SourceGrid.AutoSizeMode.None;
                _grid.Columns[1].MinimalWidth = 0;
                _grid.Columns[1].MaximalWidth = RowHeaderColumnWidth;
                _grid.Columns[1].Width        = RowHeaderColumnWidth;

                var rowIndex = rowIndexOffset;
                foreach (var rowHeader in rowHeaders)
                {
                    _grid[rowIndex, 0] = new SourceGrid.Cells.RowHeader(rowHeader.Key)
                    {
                        RowSpan = rowHeader.Count()
                    };
                    foreach (var secondRowHeader in rowHeader)
                    {
                        var secondRowHeaderCell = new SourceGrid.Cells.RowHeader(secondRowHeader);
                        secondRowHeaderCell.View = new SuperscriptRowHeaderCellView();
                        _grid[rowIndex, 1]       = secondRowHeaderCell;
                        rowIndex++;
                    }
                }
            }

            if (HasColHeaders)
            {
                for (var i = 0 + colIndexOffset; i < _grid.ColumnsCount; i++)
                {
                    _grid[0, i] = null;
                }

                for (var dataColIndex = 0; dataColIndex < dataSourceColCount; dataColIndex++)
                {
                    _grid[0, dataColIndex + colIndexOffset] = new SourceGrid.Cells.Header(_viewModel.GetColumnHeaderText(dataColIndex));
                }
            }

            for (var row = 0; row < dataSourceRowCount; row++)
            {
                for (var col = 0; col < dataSourceColCount; col++)
                {
                    var cellDisplay = _viewModel.GetCellDisplay(col, row);
                    var cell        = new SourceGrid.Cells.Cell(cellDisplay.Text);
                    if (cellDisplay.Traits.HasFlag(CellTraits.Empty))
                    {
                        BindEmptyCell(cell, cellDisplay, col, row);
                    }
                    else
                    {
                        BindCellWithCellDisplay(cell, cellDisplay, col, row);
                    }
                    _cellDisplays[Tuple.Create(col, row)] = Tuple.Create(cell, cellDisplay);
                    cellDisplay.GridCellObject            = cell;
                    var gridRow = row;
                    var gridCol = col;
                    TransformModelToGrid(ref gridCol, ref gridRow);
                    _grid[gridRow, gridCol] = cell;
                }
            }
            _grid.PerformResize();
        }
예제 #11
0
        private void btLoad_Click(object sender, System.EventArgs e)
        {
            grid.Redim(0, 0);
            //Visual properties shared between all the cells
            SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
            view.BackColor = Color.Snow;

            //Editor (IDataModel) shared between all the cells
            SourceGrid.Cells.Editors.TextBox editor = new
            SourceGrid.Cells.Editors.TextBox(typeof(string));

            grid.Redim(int.Parse(txtRows.Text), int.Parse(txtCols.Text));

            if (chkAddHeaders.Checked && grid.RowsCount > 0 &&
                        grid.ColumnsCount > 0)
            {
                grid.FixedRows = 1;
                grid.FixedColumns = 1;

                for (int r = grid.FixedRows; r < grid.RowsCount; r++)
                    grid[r, 0] = new SourceGrid.Cells.RowHeader(r);
                for (int c = grid.FixedColumns; c < grid.ColumnsCount; c++)
                {
                    SourceGrid.Cells.ColumnHeader header = new
                    SourceGrid.Cells.ColumnHeader(c);
                    header.AutomaticSortEnabled = false;
                    grid[0, c] = header;
                }
                grid[0, 0] = new SourceGrid.Cells.Header();
            }
            else
            {
                grid.FixedRows = 0;
                grid.FixedColumns = 0;
            }

            for (int r = grid.FixedRows; r < grid.RowsCount; r++)
                for (int c = grid.FixedColumns; c < grid.ColumnsCount; c++)
                {
                    grid[r, c] = new SourceGrid.Cells.Cell(r.ToString() + "," +
                    c.ToString());
                    grid[r, c].Editor = editor;
                    grid[r, c].View = view;
                }
            grid.Selection.Focus(new SourceGrid.Position(0, 0), true);
        }
예제 #12
0
        private void frmSampleGrid1_Load(object sender, System.EventArgs e)
        {
            string[] l_CountryList = new string[] { "Italy", "France", "Spain", "UK", "Argentina", "Mexico", "Switzerland", "Brazil", "Germany", "Portugal", "Sweden", "Austria" };

            grid1.RowsCount     = 1;
            grid1.ColumnsCount  = 10;
            grid1.FixedRows     = 1;
            grid1.FixedColumns  = 1;
            grid1.SelectionMode = SourceGrid.GridSelectionMode.Row;
            grid1.AutoStretchColumnsToFitWidth = true;
            grid1.Columns[0].AutoSizeMode      = SourceGrid.AutoSizeMode.None;
            grid1.Columns[0].Width             = 25;

            grid1.Controller.AddController(new KeyDeleteController());

            //TODO
            ////Enable Drag and Drop
            //grid1.GridController.AddController(SourceGrid.Controllers.SelectionDrag.Cut);
            //grid1.GridController.AddController(SourceGrid.Controllers.SelectionDrop.Default);


            #region Create Grid Style, Views and Controllers
            //Views
            mView_Price = new SourceGrid.Cells.Views.Cell();
            mView_Price.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleRight;


            mController_Link           = new SourceGrid.Cells.Controllers.Button();
            mController_Link.Executed += new EventHandler(mController_Link_Click);
            #endregion

            #region Create Header Row and Editor
            SourceGrid.Cells.Header l_00Header = new SourceGrid.Cells.Header(null);
            grid1[0, 0] = l_00Header;

            mEditor_Id = SourceGrid.Cells.Editors.Factory.Create(typeof(int));
            mEditor_Id.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.AnyKey | SourceGrid.EditableMode.SingleClick;
            grid1[0, 1]             = new SourceGrid.Cells.ColumnHeader("ID (int)");

            mEditor_Name = SourceGrid.Cells.Editors.Factory.Create(typeof(string));
            mEditor_Name.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.AnyKey | SourceGrid.EditableMode.SingleClick;
            grid1[0, 2] = new SourceGrid.Cells.ColumnHeader("NAME (string)");

            mEditor_Address = SourceGrid.Cells.Editors.Factory.Create(typeof(string));
            mEditor_Address.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.AnyKey | SourceGrid.EditableMode.SingleClick;
            grid1[0, 3] = new SourceGrid.Cells.ColumnHeader("ADDRESS (string)");

            mEditor_City = SourceGrid.Cells.Editors.Factory.Create(typeof(string));
            mEditor_City.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.AnyKey | SourceGrid.EditableMode.SingleClick;
            grid1[0, 4] = new SourceGrid.Cells.ColumnHeader("CITY (string)");

            mEditor_BirthDay = SourceGrid.Cells.Editors.Factory.Create(typeof(DateTime));
            mEditor_BirthDay.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.AnyKey | SourceGrid.EditableMode.SingleClick;
            grid1[0, 5] = new SourceGrid.Cells.ColumnHeader("BIRTHDATE (DateTime)");

            mEditor_Country = new SourceGrid.Cells.Editors.ComboBox(typeof(string), l_CountryList, false);
            mEditor_Country.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.AnyKey | SourceGrid.EditableMode.SingleClick;
            grid1[0, 6] = new SourceGrid.Cells.ColumnHeader("COUNTRY (string + combobox)");

            mEditor_Price = new SourceGrid.Cells.Editors.TextBoxCurrency(typeof(double));
            mEditor_Price.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.AnyKey | SourceGrid.EditableMode.SingleClick;
            grid1[0, 7] = new SourceGrid.Cells.ColumnHeader("$ PRICE (double)");

            grid1[0, 8] = new SourceGrid.Cells.ColumnHeader("Selected");

            grid1[0, 9] = new SourceGrid.Cells.ColumnHeader("WebSite");
            #endregion

            //Read Data From xml
            System.IO.StreamReader reader = new System.IO.StreamReader(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsFormsSample.GridSamples.SampleData.xml"));
            System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
            xmlDoc.LoadXml(reader.ReadToEnd());
            reader.Close();
            System.Xml.XmlNodeList rows = xmlDoc.SelectNodes("//row");
            grid1.RowsCount = rows.Count + 1;
            int rowsCount = 1;
            foreach (System.Xml.XmlNode l_Node in rows)
            {
                #region Pupulate RowsCount
                grid1[rowsCount, 0] = new SourceGrid.Cells.RowHeader(null);

                grid1[rowsCount, 1] = new SourceGrid.Cells.Cell(rowsCount, mEditor_Id);

                grid1[rowsCount, 2] = new SourceGrid.Cells.Cell(l_Node.Attributes["ContactName"].InnerText, mEditor_Name);

                grid1[rowsCount, 3] = new SourceGrid.Cells.Cell(l_Node.Attributes["Address"].InnerText, mEditor_Address);

                grid1[rowsCount, 4] = new SourceGrid.Cells.Cell(l_Node.Attributes["City"].InnerText, mEditor_City);

                grid1[rowsCount, 5] = new SourceGrid.Cells.Cell(DateTime.Today, mEditor_BirthDay);

                grid1[rowsCount, 6] = new SourceGrid.Cells.Cell(l_Node.Attributes["Country"].InnerText, mEditor_Country);

                grid1[rowsCount, 7]      = new SourceGrid.Cells.Cell(25.0, mEditor_Price);
                grid1[rowsCount, 7].View = mView_Price;

                grid1[rowsCount, 8] = new SourceGrid.Cells.CheckBox(null, false);

                grid1[rowsCount, 9] = new SourceGrid.Cells.Link(l_Node.Attributes["website"].InnerText);
                grid1[rowsCount, 9].AddController(mController_Link);
                #endregion

                rowsCount++;
            }

            grid1.AutoSizeCells();
        }
예제 #13
0
		private void btLoad_Click(object sender, System.EventArgs e)
		{
			using (var counter = new PerformanceCounter())
			{
				grid.Redim(0, 0);
				//Visual properties shared between all the cells
				SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
				view.BackColor = Color.Snow;

				//Editor (IDataModel) shared between all the cells
				SourceGrid.Cells.Editors.TextBox editor = new
					SourceGrid.Cells.Editors.TextBox(typeof(string));

				grid.Redim(int.Parse(txtRows.Text), int.Parse(txtCols.Text));

				if (chkAddHeaders.Checked && grid.RowsCount > 0 &&
				    grid.ColumnsCount > 0)
				{
					grid.FixedRows = 1;
					grid.FixedColumns = 1;

					for (int r = grid.FixedRows; r < grid.RowsCount; r++)
						grid[r, 0] = new SourceGrid.Cells.RowHeader(r);

					for (int c = grid.FixedColumns; c < grid.ColumnsCount; c++)
					{
						SourceGrid.Cells.ColumnHeader header = new
							SourceGrid.Cells.ColumnHeader(c);
						header.AutomaticSortEnabled = false;
						grid[0, c] = header;
					}
					grid[0, 0] = new SourceGrid.Cells.Header();
				}
				else
				{
					grid.FixedRows = 0;
					grid.FixedColumns = 0;
				}

				for (int r = grid.FixedRows; r < grid.RowsCount; r++)
					for (int c = grid.FixedColumns; c < grid.ColumnsCount; c++)
				{
					grid[r, c] = new SourceGrid.Cells.Cell(r.ToString() + "," +
					                                       c.ToString());
					grid[r, c].Editor = editor;
					grid[r, c].View = view;
					var span = 3;
					if (chkAddColspan.Checked && (c + span < grid.ColumnsCount))
					{
						if (r % 2 == 0)
						{
							grid[r, c].ColumnSpan = span;
							c += span;
						}
					}
				}
				grid.Selection.Focus(new SourceGrid.Position(0, 0), true);
				this.toolStripStatusLabelBuildTime.Text = string.Format(
					"Rows added in {0} ms", counter.GetMilisec());
			}
		}
예제 #14
0
		private void frmSampleGrid1_Load(object sender, System.EventArgs e)
		{
			string[] l_CountryList = new string[]{"Italy","France","Spain","UK","Argentina","Mexico", "Switzerland", "Brazil", "Germany","Portugal","Sweden","Austria"};

			grid1.RowsCount = 1;
			grid1.ColumnsCount = 10;
			grid1.FixedRows = 1;
			grid1.FixedColumns = 1;
			grid1.SelectionMode = SourceGrid.GridSelectionMode.Row;
			grid1.AutoStretchColumnsToFitWidth = true;
			grid1.Columns[0].AutoSizeMode = SourceGrid.AutoSizeMode.None;
			grid1.Columns[0].Width = 25;

            grid1.Controller.AddController(new KeyDeleteController());
		
            //TODO
            ////Enable Drag and Drop
            //grid1.GridController.AddController(SourceGrid.Controllers.SelectionDrag.Cut);
            //grid1.GridController.AddController(SourceGrid.Controllers.SelectionDrop.Default);


			#region Create Grid Style, Views and Controllers
			//Views
			mView_Price = new SourceGrid.Cells.Views.Cell();
			mView_Price.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleRight;


			mController_Link = new SourceGrid.Cells.Controllers.Button();
			mController_Link.Executed += new EventHandler(mController_Link_Click);
			#endregion

			#region Create Header Row and Editor
			SourceGrid.Cells.Header l_00Header = new SourceGrid.Cells.Header(null);
			grid1[0,0] = l_00Header;

            mEditor_Id = SourceGrid.Cells.Editors.Factory.Create(typeof(int));
			mEditor_Id.EditableMode = SourceGrid.EditableMode.Focus|SourceGrid.EditableMode.AnyKey|SourceGrid.EditableMode.SingleClick;
			grid1[0,1] = new SourceGrid.Cells.ColumnHeader("ID (int)");

            mEditor_Name = SourceGrid.Cells.Editors.Factory.Create(typeof(string));
			mEditor_Name.EditableMode = SourceGrid.EditableMode.Focus|SourceGrid.EditableMode.AnyKey|SourceGrid.EditableMode.SingleClick;
			grid1[0,2] = new SourceGrid.Cells.ColumnHeader("NAME (string)");

            mEditor_Address = SourceGrid.Cells.Editors.Factory.Create(typeof(string));
			mEditor_Address.EditableMode = SourceGrid.EditableMode.Focus|SourceGrid.EditableMode.AnyKey|SourceGrid.EditableMode.SingleClick;
			grid1[0,3] = new SourceGrid.Cells.ColumnHeader("ADDRESS (string)");

            mEditor_City = SourceGrid.Cells.Editors.Factory.Create(typeof(string));
			mEditor_City.EditableMode = SourceGrid.EditableMode.Focus|SourceGrid.EditableMode.AnyKey|SourceGrid.EditableMode.SingleClick;
			grid1[0,4] = new SourceGrid.Cells.ColumnHeader("CITY (string)");

			mEditor_BirthDay = SourceGrid.Cells.Editors.Factory.Create(typeof(DateTime));
			mEditor_BirthDay.EditableMode = SourceGrid.EditableMode.Focus|SourceGrid.EditableMode.AnyKey|SourceGrid.EditableMode.SingleClick;
			grid1[0,5] = new SourceGrid.Cells.ColumnHeader("BIRTHDATE (DateTime)");

			mEditor_Country = new SourceGrid.Cells.Editors.ComboBox(typeof(string),l_CountryList,false);
			mEditor_Country.EditableMode = SourceGrid.EditableMode.Focus|SourceGrid.EditableMode.AnyKey|SourceGrid.EditableMode.SingleClick;
			grid1[0,6] = new SourceGrid.Cells.ColumnHeader("COUNTRY (string + combobox)");

			mEditor_Price = new SourceGrid.Cells.Editors.TextBoxCurrency(typeof(double));
			mEditor_Price.EditableMode = SourceGrid.EditableMode.Focus|SourceGrid.EditableMode.AnyKey|SourceGrid.EditableMode.SingleClick;
			grid1[0,7] = new SourceGrid.Cells.ColumnHeader("$ PRICE (double)");

			grid1[0,8] = new SourceGrid.Cells.ColumnHeader("Selected");

			grid1[0,9] = new SourceGrid.Cells.ColumnHeader("WebSite");
			#endregion

			//Read Data From xml
			System.IO.StreamReader reader = new System.IO.StreamReader(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsFormsSample.GridSamples.SampleData.xml"));
			System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
			xmlDoc.LoadXml(reader.ReadToEnd());
			reader.Close();
			System.Xml.XmlNodeList rows = xmlDoc.SelectNodes("//row");
			grid1.RowsCount = rows.Count+1;
			int rowsCount = 1;
			foreach(System.Xml.XmlNode l_Node in rows)
			{
				#region Pupulate RowsCount
				grid1[rowsCount,0] = new SourceGrid.Cells.RowHeader(null);

				grid1[rowsCount,1] = new SourceGrid.Cells.Cell(rowsCount, mEditor_Id);

				grid1[rowsCount,2] = new SourceGrid.Cells.Cell(l_Node.Attributes["ContactName"].InnerText, mEditor_Name);

				grid1[rowsCount,3] = new SourceGrid.Cells.Cell(l_Node.Attributes["Address"].InnerText, mEditor_Address);

				grid1[rowsCount,4] = new SourceGrid.Cells.Cell(l_Node.Attributes["City"].InnerText, mEditor_City);

				grid1[rowsCount,5] = new SourceGrid.Cells.Cell(DateTime.Today, mEditor_BirthDay);

				grid1[rowsCount,6] = new SourceGrid.Cells.Cell(l_Node.Attributes["Country"].InnerText, mEditor_Country);

				grid1[rowsCount,7] = new SourceGrid.Cells.Cell(25.0, mEditor_Price);
                grid1[rowsCount, 7].View = mView_Price;

				grid1[rowsCount,8] = new SourceGrid.Cells.CheckBox(null, false);

				grid1[rowsCount,9] = new SourceGrid.Cells.Link(l_Node.Attributes["website"].InnerText);
				grid1[rowsCount,9].AddController(mController_Link);
				#endregion

				rowsCount++;
			}

            grid1.AutoSizeCells();
		}
예제 #15
0
        private void btLoad_Click(object sender, System.EventArgs e)
        {
            using (var counter = new PerformanceCounter())
            {
                grid.Redim(0, 0);
                //Visual properties shared between all the cells
                SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
                view.BackColor = Color.Snow;

                //Editor (IDataModel) shared between all the cells
                SourceGrid.Cells.Editors.TextBox editor = new
                                                          SourceGrid.Cells.Editors.TextBox(typeof(string));

                grid.Redim(int.Parse(txtRows.Text), int.Parse(txtCols.Text));

                if (chkAddHeaders.Checked && grid.RowsCount > 0 &&
                    grid.ColumnsCount > 0)
                {
                    grid.FixedRows    = 1;
                    grid.FixedColumns = 1;

                    for (int r = grid.FixedRows; r < grid.RowsCount; r++)
                    {
                        grid[r, 0] = new SourceGrid.Cells.RowHeader(r);
                    }

                    for (int c = grid.FixedColumns; c < grid.ColumnsCount; c++)
                    {
                        SourceGrid.Cells.ColumnHeader header = new
                                                               SourceGrid.Cells.ColumnHeader(c);
                        header.AutomaticSortEnabled = false;
                        grid[0, c] = header;
                    }
                    grid[0, 0] = new SourceGrid.Cells.Header();
                }
                else
                {
                    grid.FixedRows    = 0;
                    grid.FixedColumns = 0;
                }

                for (int r = grid.FixedRows; r < grid.RowsCount; r++)
                {
                    for (int c = grid.FixedColumns; c < grid.ColumnsCount; c++)
                    {
                        grid[r, c] = new SourceGrid.Cells.Cell(r.ToString() + "," +
                                                               c.ToString());
                        grid[r, c].Editor = editor;
                        grid[r, c].View   = view;
                        var span = 3;
                        if (chkAddColspan.Checked && (c + span < grid.ColumnsCount))
                        {
                            if (r % 2 == 0)
                            {
                                grid[r, c].ColumnSpan = span;
                                c += span;
                            }
                        }
                    }
                }
                grid.Selection.Focus(new SourceGrid.Position(0, 0), true);
                this.toolStripStatusLabelBuildTime.Text = string.Format(
                    "Rows added in {0} ms", counter.GetMilisec());
            }
        }
예제 #16
0
        /// <summary>
        /// Occurs when loading this control.
        /// </summary>
        /// <param name="eventArgs">
        /// The <see cref="EventArgs"/>.
        /// </param>
        protected override void OnLoad(EventArgs eventArgs)
        {
            const int numberOfRows = 6;
            const int numberOfCols = 4;
            grid.Redim(numberOfRows, numberOfCols);
            grid.FixedRows = 1;
            grid.FixedColumns = 1;
            grid.SelectionMode = SourceGrid.GridSelectionMode.Row;
            grid.ToolTipText = "Linked Controls";

            grid[0, 0] = new SourceGrid.Cells.Header(null);

            // Create column header
            for (int i = 0; i < numberOfCols; i++)
            {
                string label;

                switch (i)
                {
                    case 1:
                        label = "Description";
                        break;
                    case 2:
                        label = "Value";
                        break;
                    case 3:
                        label = "Unit";
                        break;
                    default:
                        label = null;
                        break;
                }

                var header = new SourceGrid.Cells.ColumnHeader(label) { AutomaticSortEnabled = false };

                grid[0, i] = header;
            }

            // Create some entries
            SourceGrid.Cells.Views.Cell visualAspect = new SourceGrid.Cells.Views.Cell();

            for (int i = 1; i < numberOfRows; i++)
            {
                string label;
                string unit;
                Control usedControl;
                SourceGrid.Cells.Controllers.ToolTipText toolTipController =
                    new SourceGrid.Cells.Controllers.ToolTipText();

                toolTipController.IsBalloon = true;

                switch (i)
                {
                    case 1:
                        label = "Numeric Up Down [3...15]";
                        unit = "µs";
                        usedControl = new NumericUpDown();
                        (usedControl as NumericUpDown).Minimum = 3;
                        (usedControl as NumericUpDown).Maximum = 15;
                        (usedControl as NumericUpDown).Increment = 2;
                        (usedControl as NumericUpDown).Value = 7;
                        break;
                    case 2:
                        label = "Text box with max. length of 15 chars.";
                        unit = ":o)";
                        usedControl = new TextBox();
                        (usedControl as TextBox).MaxLength = 15;
                        (usedControl as TextBox).Text = "Some Text";
                        break;
                    case 3:
                        label = "Disabled text box";
                        unit = "^_^";
                        usedControl = new TextBox();
                        (usedControl as TextBox).Enabled = false;
                        (usedControl as TextBox).Text = "Some disabled Text";
                        break;
                    case 4:
                        label = "Combo box with auto complete";
                        unit = "Prio.";
                        usedControl = new ComboBox();
                        (usedControl as ComboBox).Items.AddRange(
                            new object[] { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" });
                        (usedControl as ComboBox).AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                        (usedControl as ComboBox).AutoCompleteSource = AutoCompleteSource.ListItems;
                        break;
                    default:
                        label = "Progress bar";
                        unit = "";
                        Random randNmbr = new Random();
                        usedControl = new ProgressBar();
                        (usedControl as ProgressBar).Value = randNmbr.Next(0, 100);
                        break;
                }

                grid[i, 1] = new SourceGrid.Cells.Cell
                    {
                        View = visualAspect, Value = label, ToolTipText = label + "..." + unit 
                    };
                grid[i, 1].AddController(toolTipController);

                grid[i, 2] = new SourceGrid.Cells.Cell();

                usedControl.Enter += delegate(object sender, EventArgs e)
                {
                    IsRechangingSelection = true;

                    foreach (RowInfo rowInfo in grid.Rows)
                    {
                        grid.Selection.SelectRow(rowInfo.Index, false);
                    }

                    foreach (LinkedControlValue lcv in grid.LinkedControls)
                    {
                        if (lcv.Control == usedControl)
                        {
                            grid.Selection.SelectRow(lcv.Position.Row, true);
                            break;
                        }
                    }

                    IsRechangingSelection = false;
                };

                grid.LinkedControls.Add(new SourceGrid.LinkedControlValue(usedControl, new SourceGrid.Position(i, 2)));

                grid[i, 3] = new SourceGrid.Cells.Cell { View = visualAspect, Value = unit };
            }

            if (grid.Columns[2].MinimalWidth < 127)
            {
                grid.Columns[2].MinimalWidth = 127;
            }

            grid.VScrollBar.ValueChanged += delegate(object sender, EventArgs valueChangedEventArgs)
            {
                // Hide all linked controls above 'new value'
                // Show all linked controls beyond 'new value'
                foreach (LinkedControlValue lcv in grid.LinkedControls)
                {
                    lcv.Control.Visible = lcv.Position.Row > grid.VScrollBar.Value;
                }

                // Reselecting works more or less when scrolling down. But what when scrolling up?
                if (grid.Selection.ActivePosition.Row <= grid.VScrollBar.Value)
                {
                    IsRechangingSelection = false;

                    foreach (LinkedControlValue lcv in grid.LinkedControls)
                    {
                        grid.Selection.SelectRow(lcv.Position.Row, false);
                    }

                    IsRechangingSelection = true;

                    grid.Selection.SelectRow(grid.VScrollBar.Value + 1, true);
                }
            };

            // Focus the custom control when changing selection
            grid.Selection.SelectionChanged += delegate(object sender, RangeRegionChangedEventArgs e)
            {
                if (!IsRechangingSelection && e.AddedRange != null && e.RemovedRange == null)
                {
                    bool isFound = false;
                    int selectedRow = -1;
                    int selectedCol = -1;
                    int[] selectedRows = e.AddedRange.GetRowsIndex();

                    if (sender is SourceGrid.Selection.SelectionBase)
                    {
                        selectedRow = (sender as SourceGrid.Selection.SelectionBase).ActivePosition.Row;
                        selectedCol = (sender as SourceGrid.Selection.SelectionBase).ActivePosition.Column;
                    }

                    if (selectedRows[0] != -1)
                    {
                        selectedRow = selectedRows[0];
                    }

                    foreach (LinkedControlValue lcv in grid.LinkedControls)
                    {
                        if (lcv.Position.Row == selectedRow)
                        {
                            // Remove focus from control
                            isFound = true;
                            lcv.Control.Focus();
                            break;
                        }
                    }

                    if (!isFound)
                    {
                        IsRechangingSelection = true;
                        grid.Selection.Focus(new Position(selectedRow, selectedCol), true);
                        IsRechangingSelection = false;
                    }
                }
            };
        }