Redim() public method

Set the number of columns and rows
public Redim ( int p_Rows, int p_Cols ) : void
p_Rows int
p_Cols int
return void
		public void SelectRow_ShouldMaintain_ActivePosition()
		{
			// set up special conditions
			var grid = new Grid();
			grid.Redim(1, 1);
			grid[0, 0] = new Cell();
			
			var form = new Form();
			form.Controls.Add(grid);
			form.Show();

			grid.SelectionMode = GridSelectionMode.Row;
			grid.Selection.EnableMultiSelection = false;
			
			
			// just assert that we have correct conditions for test, 
			// active position should not be empty
			grid.Selection.Focus(new Position(0, 0), true);
			Assert.AreEqual(new Position(0, 0), grid.Selection.ActivePosition);
			
			// this method causes first row to be selected. Should not fail 
			// it failed once in RowSelection.SelectRow method
			// As call to ResetSelection asked to maintain focus, a stack overflow was raised
			grid.Selection.SelectRow(0, true);
			Assert.AreEqual(new Position(0, 0), grid.Selection.ActivePosition);
			
			// destroy
			form.Close();
			form.Dispose();
		}
		public void TestTabMovement_DoesLoopCorrectly_ThroughSpannedRowCells()
		{
			using (var form = new Form())
			{
				
				Grid grid1 = new Grid();
				grid1.Redim(40,3);
				grid1.FixedColumns = 1;
				grid1.FixedRows = 1;

				Random rnd = new Random();
				for (int r = 0; r < grid1.RowsCount/2; r++)
				{
					for (int c = 0; c < grid1.ColumnsCount; c++)
					{
						grid1[r * 2, c] = new SourceGrid.Cells.Cell(r*c);
						grid1[r * 2, c].RowSpan = 2;
					}
				}
				
				form.Controls.Add(grid1);
				form.Show();
				
				Assert.AreEqual(true, grid1.Selection.Focus(new Position(0, 0), true));
				Assert.AreEqual(new Position(0, 0), grid1.Selection.ActivePosition);
				
				Assert.AreEqual(true, grid1.Selection.Focus(new Position(1, 0), true));
				Assert.AreEqual(new Position(1, 0), grid1.Selection.ActivePosition);
				
				form.Close();
			}
		}
		public void GetCell_NonExistent()
		{
			SourceGrid.Grid grid1 = new Grid();
			grid1.Redim(2, 2);
			
			Assert.AreEqual(null, grid1.GetCell(0, 0));
		}
		public void GetCell_OutOfBounds()
		{
			Grid grid = new Grid();
			grid.Redim(5, 5);
			
			Assert.AreEqual(null, grid.GetCell(new Position(10, 10)));
		}
        private void DoFull()
        {
            grid1.Redim(20, 4);
            grid1.FixedRows = 1;

            grid1[0, 0]            = new MyHeader("1");
            grid1[0, 0].ColumnSpan = 3;
            grid1[0, 0].AddController(new SourceGrid.Cells.Controllers.SortableHeader());
            grid1[0, 3] = new MyHeader("2");
            grid1[0, 3].AddController(new SourceGrid.Cells.Controllers.SortableHeader());

            for (int r = 1; r < grid1.RowsCount; r++)
            {
                if (r % 2 == 0)
                {
                    grid1[r, 0]            = new SourceGrid.Cells.Cell("nospan" + r.ToString(), typeof(string));
                    grid1[r, 1]            = new SourceGrid.Cells.Cell("span" + r.ToString(), typeof(string));
                    grid1[r, 1].ColumnSpan = 2;
                }
                else
                {
                    grid1[r, 0]            = new SourceGrid.Cells.Cell("span" + r.ToString(), typeof(string));
                    grid1[r, 0].ColumnSpan = 2;
                    grid1[r, 2]            = new SourceGrid.Cells.Cell("nospan" + r.ToString(), typeof(string));
                }

                grid1[r, 3] = new SourceGrid.Cells.CheckBox("CheckBox Column/Row Span" + r.ToString(), false);
            }

            grid1.AutoSizeCells();
        }
		public void InsertOverlappingCell()
		{
			SourceGrid.Grid grid1 = new Grid();
			grid1.Redim(2, 2);
			
			// this cell should span both to the right, and to the left
			grid1[0, 0] = new SourceGrid.Cells.Cell("Text Span", typeof(string));;
			grid1[0, 0].ColumnSpan = 2;
			
			grid1[0, 1] = new SourceGrid.Cells.Cell("This should throw OverlappingCellException");
		}
		public void ModifyRowSpan_ToCauseOverlapping()
		{
			SourceGrid.Grid grid1 = new Grid();
			grid1.Redim(6, 2);
			
			// this cell should span both to the right, and to the left
			grid1[4, 0] = new SourceGrid.Cells.Cell("cell to span", typeof(string));
			grid1[5, 0] = new SourceGrid.Cells.Cell("cell to overlap", typeof(string));
			
			// this should throw exception
			grid1[4, 0].RowSpan = 2;
		}
		public void ModifyColumnSpan_ToCauseOverlapping()
		{
			SourceGrid.Grid grid1 = new Grid();
			grid1.Redim(2, 6);
			
			// this cell should span both to the right, and to the left
			grid1[0, 4] = new SourceGrid.Cells.Cell("cell to span", typeof(string));
			grid1[0, 5] = new SourceGrid.Cells.Cell("cell to overlap", typeof(string));
			
			// this should throw exception
			grid1[0, 4].ColumnSpan = 2;
		}
		public void SubscriptionToEventsAreNotChanged_After_SelectionIsChanged()
		{
			int selectionChangedCount = 0;
			Grid grid = new Grid();
			grid.Redim(5, 5);
			grid[1, 1] = new SourceGrid.Cells.Cell("b");
			
			grid.Selection.SelectionChanged += delegate { selectionChangedCount++; };
			grid.SelectionMode = GridSelectionMode.Row;
			grid.Selection.SelectCell(new Position(1, 1), true);
			Assert.AreEqual(1, selectionChangedCount);
			
		}
        public void LoadList()
        {
            if (m_ItemType == null)
            {
                throw new ApplicationException("ItemType is null");
            }
            if (m_List == null)
            {
                m_List = new ArrayList();
            }

            if (m_Properties.Length != m_Editors.Length)
            {
                throw new ApplicationException("Properteis.Length != Editors.Length");
            }

            grid.FixedRows    = 1;
            grid.FixedColumns = 0;
            grid.Redim(m_List.Count + grid.FixedRows, m_Properties.Length + grid.FixedColumns);


            //HeaderCell
            //grid[0,0] = new Cells.Header();



            for (int i = 0; i < m_Properties.Length; i++)
            {
                Cells.ColumnHeader l_Header = new Cells.ColumnHeader(m_Properties[i].Name.Replace("_", " "));   //GetCustomAttributes(typeof(ListEditor), false));
                grid[0, i + grid.FixedColumns] = l_Header;

                l_Header.AutomaticSortEnabled = false;
//				//If the column type support the IComparable then I can use the value to sort the column, otherwise I use the string representation for sort.
//				if (typeof(IComparable).IsAssignableFrom(m_Properties[i].PropertyType))
//					l_Header.Comparer = new ValueCellComparer();
//				else
//					l_Header.Comparer = new DisplayStringCellComparer();
            }

            for (int r = 0; r < m_List.Count; r++)
            {
                PopulateRow(r + grid.FixedRows, m_List[r]);
            }

            grid.AutoStretchColumnsToFitWidth = true;
            grid.AutoSizeCells();
        }
		public void GetCell()
		{
			SourceGrid.Grid grid1 = new Grid();
			grid1.Redim(2, 2);
			
			Cell visibleCell = new SourceGrid.Cells.Cell("Text Span", typeof(string));
			
			// this cell should span both to the right, and to the left
			grid1[0, 0] = visibleCell;
			grid1[0, 0].RowSpan = 2;
			grid1[0, 0].ColumnSpan = 2;
			
			
			Assert.AreEqual(visibleCell, grid1.GetCell(0, 0));
			Assert.AreEqual(visibleCell, grid1.GetCell(0, 1));
			Assert.AreEqual(visibleCell, grid1.GetCell(1, 0));
			Assert.AreEqual(visibleCell, grid1.GetCell(1, 1));
		}
		public void SelectSpannedCells_SingleCell()
		{
			// just select a single cell. Should select whole spanned cell
			Grid grid1 = new Grid();
			grid1.Redim(6, 6);

			grid1[0, 0] = new SourceGrid.Cells.Cell();
			grid1[0, 0].ColumnSpan = 3;
			grid1[0, 0].RowSpan = 3;

			grid1[0, 3] = new SourceGrid.Cells.Cell();
			grid1[0, 3].ColumnSpan = 3;
			grid1[0, 3].RowSpan = 3;
			
			grid1.Selection.SelectCell(new Position(0, 0), true);
			RangeRegion region = grid1.Selection.GetSelectionRegion();
			Assert.AreEqual(1, region.Count);
			Assert.AreEqual(new Range(0, 0, 2, 2), region[0]);
		}
		public void SelectSpannedCells_SingleCell_DoubleSelection()
		{
			// select at two positions the same cell
			Grid grid1 = new Grid();
			grid1.Redim(6, 6);

			grid1[0, 0] = new SourceGrid.Cells.Cell();
			grid1[0, 0].ColumnSpan = 3;
			grid1[0, 0].RowSpan = 3;

			grid1[0, 3] = new SourceGrid.Cells.Cell();
			grid1[0, 3].ColumnSpan = 3;
			grid1[0, 3].RowSpan = 3;
			
			grid1.Selection.SelectRange(new Range(0, 0, 0, 1), true);
			
			RangeRegion region = grid1.Selection.GetSelectionRegion();
			Assert.AreEqual(1, region.Count);
			Assert.AreEqual(new Range(0, 0, 2, 2), region[0]);
		}
		public void ResetSelection_DoesNotInfiniteLoop()
		{
			// set up special conditions
			var grid = new Grid();
			grid.Redim(1, 1);
			grid[0, 0] = new Cell();
			
			var form = new Form();
			form.Controls.Add(grid);
			form.Show();

			grid.SelectionMode = GridSelectionMode.Row;
			grid.Selection.EnableMultiSelection = false;
			
			// this method causes first row to be selected. Should not fail 
			// it failed once in RowSelection.SelectRow method
			// As call to ResetSelection asked to maintain focus, a stack overflow was raised
			grid.Selection.Focus(new Position(0, 0), false);
			
			// destroy
			form.Close();
			form.Dispose();
		}
		public void AreSpannedCells_CorrectlyRemoved()
		{
			SourceGrid.Grid grid1 = new Grid();
			grid1.Redim(2, 2);
			
			grid1[0, 0] = new Cell();
			grid1[0, 0].ColumnSpan = 2;
			grid1[0, 0] = null;
			
			// this should be true. But is not, at the moment of writing
			Assert.AreEqual(null, grid1.GetCell(0, 1));
			// this should not throw exception
			grid1[0, 1] = new Cell("my new cell");
		}
		public void InsertNullCell()
		{
			SourceGrid.Grid grid1 = new Grid();
			grid1.Redim(2, 2);
			
			// this should not throw exception
			grid1[0, 0] = null;
		}
        /// <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;
                    }
                }
            };
        }
Beispiel #18
0
        private void DoFull()
        {
            grid1.Redim(20, 12);
            grid1.FixedRows = 2;

            //1 Header Row
            grid1[0, 0]            = new MyHeader("3 Column Header");
            grid1[0, 0].ColumnSpan = 3;
            grid1[0, 3]            = new MyHeader("5 Column Header");
            grid1[0, 3].ColumnSpan = 5;
            grid1[0, 8]            = new MyHeader("1 Column Header");
            grid1[0, 9]            = new MyHeader("1 Column Header");

            //2 Header Row
            grid1[1, 0]  = new MyHeader("1");
            grid1[1, 1]  = new MyHeader("2");
            grid1[1, 2]  = new MyHeader("3");
            grid1[1, 3]  = new MyHeader("4");
            grid1[1, 4]  = new MyHeader("5");
            grid1[1, 5]  = new MyHeader("6");
            grid1[1, 6]  = new MyHeader("7");
            grid1[1, 7]  = new MyHeader("8");
            grid1[1, 8]  = new MyHeader("9");
            grid1[1, 9]  = new MyHeader("10");
            grid1[1, 10] = new MyHeader("11");
            grid1[1, 11] = new MyHeader("12");

            SourceGrid.Cells.Views.Cell viewImage = new SourceGrid.Cells.Views.Cell();

            SourceGrid.Cells.Controllers.CustomEvents clickEvent = new SourceGrid.Cells.Controllers.CustomEvents();
            clickEvent.Click += new EventHandler(clickEvent_Click);

            for (int r = 2; r < grid1.RowsCount; r = r + 2)
            {
                grid1[r, 0]            = new SourceGrid.Cells.Cell(r.ToString(), typeof(string));
                grid1[r, 0].ColumnSpan = 2;

                grid1[r + 1, 0]            = new SourceGrid.Cells.Cell();
                grid1[r + 1, 0].ColumnSpan = 2;

                grid1[r, 2]            = new SourceGrid.Cells.CheckBox("CheckBox Column/Row Span", false);
                grid1[r, 2].ColumnSpan = 2;
                grid1[r, 2].RowSpan    = 2;

                grid1[r, 4]            = new SourceGrid.Cells.Link("Link Column/Row Span");
                grid1[r, 4].ColumnSpan = 2;
                grid1[r, 4].RowSpan    = 2;
                grid1[r, 4].AddController(clickEvent);

                grid1[r, 6]            = new SourceGrid.Cells.Button("Button Column/Row Span");
                grid1[r, 6].ColumnSpan = 2;
                grid1[r, 6].RowSpan    = 2;
                grid1[r, 6].AddController(clickEvent);

                grid1[r, 8]            = new SourceGrid.Cells.Cell("Image Column/Row Span");
                grid1[r, 8].View       = viewImage;
                grid1[r, 8].Image      = Properties.Resources.FACE02.ToBitmap();
                grid1[r, 8].ColumnSpan = 2;
                grid1[r, 8].RowSpan    = 2;

                grid1[r, 10]            = new SourceGrid.Cells.Cell("Text Span", typeof(string));
                grid1[r, 10].ColumnSpan = 2;
                grid1[r, 10].RowSpan    = 2;
            }

            grid1.ClipboardMode = SourceGrid.ClipboardMode.All;
            grid1.AutoSizeCells();
        }