예제 #1
0
            /// <summary>
            /// Insert the specified number of rows at the specified position
            /// </summary>
            /// <param name="p_StartIndex"></param>
            /// <param name="p_Count"></param>
            public void InsertRange(int p_StartIndex, int p_Count)
            {
                RowInfo[] rows = new RowInfo[p_Count];
                for (int i = 0; i < rows.Length; i++)
                    rows[i] = CreateRow();

                InsertRange(p_StartIndex, rows);
            }
예제 #2
0
		/// <summary>
		/// Insert the specified number of rows at the specified position
		/// </summary>
		public void InsertRange(int startIndex, int count)
		{
			RowInfo[] rows = new RowInfo[count];
			for (int i = 0; i < rows.Length; i++)
				rows[i] = CreateRow();

			base.InsertRange(startIndex, rows);
			// Ensure that grid grows when rows are inserted
			this.Grid.GrowGrid();
			
			this.Grid.SpannedCellReferences.MoveDownSpannedRanges(startIndex, count);
			this.Grid.SpannedCellReferences.ExpandSpannedRows(startIndex, count);
			
			
		}
예제 #3
0
		/// <summary>
		/// Fired when calling SortRangeRows method. If the range contains all the columns this method move directly the row object otherwise move each cell.
		/// </summary>
		/// <param name="e"></param>
		protected override void OnSortingRangeRows(SortRangeRowsEventArgs e)
		{
			base.OnSortingRangeRows(e);

			if (CustomSort)
				return;

			if (e.KeyColumn > e.Range.End.Column && e.KeyColumn < e.Range.Start.Column)
				throw new ArgumentException("Invalid range", "e.KeyColumn");

			System.Collections.IComparer cellComparer = e.CellComparer;
			if (cellComparer == null)
				cellComparer = new ValueCellComparer();

			//Sort all the columns (in this case I move directly the row object)
			if (e.Range.ColumnsCount == ColumnsCount)
			{
				RowInfo[] rowInfoToSort = new RowInfo[e.Range.End.Row-e.Range.Start.Row+1];
				Cells.ICell[] cellKeys = new Cells.ICell[e.Range.End.Row-e.Range.Start.Row+1];

				int zeroIndex = 0;
				for (int r = e.Range.Start.Row; r <= e.Range.End.Row;r++)
				{
					cellKeys[zeroIndex] = this[r, e.KeyColumn];

					rowInfoToSort[zeroIndex] = Rows[r];
					zeroIndex++;
				}

				Array.Sort(cellKeys, rowInfoToSort, 0, cellKeys.Length, cellComparer);

				//Apply sort
				if (e.Ascending)
				{
					for (zeroIndex = 0; zeroIndex < rowInfoToSort.Length; zeroIndex++)
					{
						Rows.Swap( rowInfoToSort[zeroIndex].Index, e.Range.Start.Row + zeroIndex);
					}
				}
				else //desc
				{
					for (zeroIndex = rowInfoToSort.Length-1; zeroIndex >= 0; zeroIndex--)
					{
						Rows.Swap( rowInfoToSort[zeroIndex].Index, e.Range.End.Row - zeroIndex);
					}
				}
			}
			else //sort only the specified range
			{
				Cells.ICell[][] l_RangeSort = new Cells.ICell[e.Range.End.Row-e.Range.Start.Row+1][];
				Cells.ICell[] l_CellsKeys = new Cells.ICell[e.Range.End.Row-e.Range.Start.Row+1];

				int zeroRowIndex = 0;
				for (int r = e.Range.Start.Row; r <= e.Range.End.Row;r++)
				{
					l_CellsKeys[zeroRowIndex] = this[r, e.KeyColumn];

					int zeroColIndex = 0;
					l_RangeSort[zeroRowIndex] = new Cells.ICell[e.Range.End.Column-e.Range.Start.Column+1];
					for (int c = e.Range.Start.Column; c <= e.Range.End.Column; c++)
					{
						l_RangeSort[zeroRowIndex][zeroColIndex] = this[r,c];
						zeroColIndex++;
					}
					zeroRowIndex++;
				}

				Array.Sort(l_CellsKeys, l_RangeSort, 0, l_CellsKeys.Length, cellComparer);

				//Apply sort
				zeroRowIndex = 0;
				if (e.Ascending)
				{
					for (int r = e.Range.Start.Row; r <= e.Range.End.Row;r++)
					{
						int zeroColIndex = 0;
						for (int c = e.Range.Start.Column; c <= e.Range.End.Column; c++)
						{
							RemoveCell(r,c);//rimuovo qualunque cella nella posizione corrente
							Cells.ICell tmp = l_RangeSort[zeroRowIndex][zeroColIndex];

							if (tmp!=null && tmp.Grid!=null && tmp.Range.Start.Row>=0 && tmp.Range.Start.Column>=0) //verifico che la cella sia valida
								RemoveCell(tmp.Range.Start.Row, tmp.Range.Start.Column);//la rimuovo dalla posizione precedente

							this[r,c] = tmp;
							zeroColIndex++;
						}
						zeroRowIndex++;
					}
				}
				else //desc
				{
					for (int r = e.Range.End.Row; r >= e.Range.Start.Row;r--)
					{
						int zeroColIndex = 0;
						for (int c = e.Range.Start.Column; c <= e.Range.End.Column; c++)
						{
							RemoveCell(r,c);//rimuovo qualunque cella nella posizione corrente
							Cells.ICell tmp = l_RangeSort[zeroRowIndex][zeroColIndex];

							if (tmp!=null && tmp.Grid!=null && tmp.Range.Start.Row >= 0 && tmp.Range.Start.Column >= 0) //verifico che la cella sia valida
								RemoveCell(tmp.Range.Start.Row, tmp.Range.Start.Column);//la rimuovo dalla posizione precedente

							this[r,c] = tmp;
							zeroColIndex++;
						}
						zeroRowIndex++;
					}
				}
			}
		}
예제 #4
0
파일: Events.cs 프로젝트: zhuangyy/Motion
 public RowInfoEventArgs(RowInfo p_RowInfo)
 {
     m_RowInfo = p_RowInfo;
 }
예제 #5
0
파일: Grid.cs 프로젝트: unixcrh/Motion
        /// <summary>
        /// Fired when calling SortRangeRows method. If the range contains all the columns this method move directly the row object otherwise move each cell.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnSortingRangeRows(SortRangeRowsEventArgs e)
        {
            base.OnSortingRangeRows(e);

            if (CustomSort)
            {
                return;
            }

            if (e.KeyColumn > e.Range.End.Column && e.KeyColumn < e.Range.Start.Column)
            {
                throw new ArgumentException("Invalid range", "e.KeyColumn");
            }

            IComparer cellComparer = e.CellComparer;

            if (cellComparer == null)
            {
                cellComparer = new ValueCellComparer();
            }

            //Sort all the columns (in this case I move directly the row object)
            if (e.Range.ColumnsCount == ColumnsCount)
            {
                RowInfo[]     rowInfoToSort = new RowInfo[e.Range.End.Row - e.Range.Start.Row + 1];
                Cells.ICell[] cellKeys      = new Cells.ICell[e.Range.End.Row - e.Range.Start.Row + 1];

                int zeroIndex = 0;
                for (int r = e.Range.Start.Row; r <= e.Range.End.Row; r++)
                {
                    cellKeys[zeroIndex] = this[r, e.KeyColumn];

                    rowInfoToSort[zeroIndex] = Rows[r];
                    zeroIndex++;
                }

                Array.Sort(cellKeys, rowInfoToSort, 0, cellKeys.Length, cellComparer);

                //Apply sort
                if (e.Ascending)
                {
                    for (zeroIndex = 0; zeroIndex < rowInfoToSort.Length; zeroIndex++)
                    {
                        Rows.Swap(rowInfoToSort[zeroIndex].Index, e.Range.Start.Row + zeroIndex);
                    }
                }
                else                 //desc
                {
                    for (zeroIndex = rowInfoToSort.Length - 1; zeroIndex >= 0; zeroIndex--)
                    {
                        Rows.Swap(rowInfoToSort[zeroIndex].Index, e.Range.End.Row - zeroIndex);
                    }
                }
            }
            else             //sort only the specified range
            {
                Cells.ICell[][] l_RangeSort = new Cells.ICell[e.Range.End.Row - e.Range.Start.Row + 1][];
                Cells.ICell[]   l_CellsKeys = new Cells.ICell[e.Range.End.Row - e.Range.Start.Row + 1];

                int zeroRowIndex = 0;
                for (int r = e.Range.Start.Row; r <= e.Range.End.Row; r++)
                {
                    l_CellsKeys[zeroRowIndex] = this[r, e.KeyColumn];

                    int zeroColIndex = 0;
                    l_RangeSort[zeroRowIndex] = new Cells.ICell[e.Range.End.Column - e.Range.Start.Column + 1];
                    for (int c = e.Range.Start.Column; c <= e.Range.End.Column; c++)
                    {
                        l_RangeSort[zeroRowIndex][zeroColIndex] = this[r, c];
                        zeroColIndex++;
                    }
                    zeroRowIndex++;
                }

                Array.Sort(l_CellsKeys, l_RangeSort, 0, l_CellsKeys.Length, cellComparer);

                //Apply sort
                zeroRowIndex = 0;
                if (e.Ascending)
                {
                    for (int r = e.Range.Start.Row; r <= e.Range.End.Row; r++)
                    {
                        int zeroColIndex = 0;
                        for (int c = e.Range.Start.Column; c <= e.Range.End.Column; c++)
                        {
                            RemoveCell(r, c);                           //rimuovo qualunque cella nella posizione corrente
                            Cells.ICell tmp = l_RangeSort[zeroRowIndex][zeroColIndex];

                            if (tmp != null && tmp.Grid != null && tmp.Range.Start.Row >= 0 && tmp.Range.Start.Column >= 0) //verifico che la cella sia valida
                            {
                                RemoveCell(tmp.Range.Start.Row, tmp.Range.Start.Column);                                    //la rimuovo dalla posizione precedente
                            }
                            this[r, c] = tmp;
                            zeroColIndex++;
                        }
                        zeroRowIndex++;
                    }
                }
                else                 //desc
                {
                    for (int r = e.Range.End.Row; r >= e.Range.Start.Row; r--)
                    {
                        int zeroColIndex = 0;
                        for (int c = e.Range.Start.Column; c <= e.Range.End.Column; c++)
                        {
                            RemoveCell(r, c);                           //rimuovo qualunque cella nella posizione corrente
                            Cells.ICell tmp = l_RangeSort[zeroRowIndex][zeroColIndex];

                            if (tmp != null && tmp.Grid != null && tmp.Range.Start.Row >= 0 && tmp.Range.Start.Column >= 0) //verifico che la cella sia valida
                            {
                                RemoveCell(tmp.Range.Start.Row, tmp.Range.Start.Column);                                    //la rimuovo dalla posizione precedente
                            }
                            this[r, c] = tmp;
                            zeroColIndex++;
                        }
                        zeroRowIndex++;
                    }
                }
            }
        }