예제 #1
0
        private int AddCore(DataGridViewRow dataGridViewRow, bool sharable)
        {
            if (dataGridView.Columns.Count == 0)
            {
                throw new InvalidOperationException("DataGridView has no columns.");
            }

            int result;

            dataGridViewRow.SetDataGridView(dataGridView);

            //
            // Add the row just before the editing row (if there is an editing row).
            //
            int editing_index = -1;

            if (DataGridView != null && DataGridView.EditingRow != null && DataGridView.EditingRow != dataGridViewRow)
            {
                editing_index = list.Count - 1;                 // always the last row
                DataGridView.EditingRow.SetIndex(list.Count);
            }

            if (editing_index >= 0)
            {
                list.Insert(editing_index, dataGridViewRow);
                result = editing_index;
            }
            else
            {
                result = list.Add(dataGridViewRow);
            }

            if (sharable && CanBeShared(dataGridViewRow))
            {
                dataGridViewRow.SetIndex(-1);
            }
            else
            {
                dataGridViewRow.SetIndex(result);
            }

            CompleteRowCells(dataGridViewRow);
            for (int i = 0; i < dataGridViewRow.Cells.Count; i++)
            {
                dataGridViewRow.Cells [i].SetOwningColumn(dataGridView.Columns [i]);
            }

            if (raiseEvent)
            {
                OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Add, dataGridViewRow));
                DataGridView.OnRowsAddedInternal(new DataGridViewRowsAddedEventArgs(result, 1));
            }

            return(result);
        }
예제 #2
0
 // FIXME: Do *not* allow insertation *after* the editing row!
 public virtual void Insert(int rowIndex, DataGridViewRow dataGridViewRow)
 {
     dataGridViewRow.SetIndex(rowIndex);
     dataGridViewRow.SetDataGridView(dataGridView);
     CompleteRowCells(dataGridViewRow);
     list.Insert(rowIndex, dataGridViewRow);
     ReIndex();
     OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Add, dataGridViewRow));
     if (raiseEvent)
     {
         DataGridView.OnRowsAddedInternal(new DataGridViewRowsAddedEventArgs(rowIndex, 1));
     }
 }
예제 #3
0
 public DataGridViewRow this [int index] {
     get {
         // Accessing a System.Windows.Forms.DataGridViewRow with this indexer causes the row to become unshared.
         // To keep the row shared, use the System.Windows.Forms.DataGridViewRowCollection.SharedRow method.
         // For more information, see Best Practices for Scaling the Windows Forms DataGridView Control.
         DataGridViewRow row = (DataGridViewRow)list [index];
         if (row.Index == -1)
         {
             row = (DataGridViewRow)row.Clone();
             row.SetIndex(index);
             list [index] = row;
         }
         return(row);
     }
 }
예제 #4
0
        public override object Clone()
        {
            DataGridViewRow row = (DataGridViewRow)MemberwiseClone();

            row.HeaderCell = (DataGridViewRowHeaderCell)HeaderCell.Clone();
            row.SetIndex(-1);

            row.cells = new DataGridViewCellCollection(row);

            foreach (DataGridViewCell cell in cells)
            {
                row.cells.Add(cell.Clone() as DataGridViewCell);
            }

            row.SetDataGridView(null);

            return(row);
        }
예제 #5
0
        public override object Clone()
        {
            DataGridViewRow row = (DataGridViewRow)MemberwiseClone();

            row.DefaultCellStyle = (DataGridViewCellStyle)DefaultCellStyle.Clone();
            row.HeaderCell       = (DataGridViewRowHeaderCell)HeaderCell.Clone();
            row.SetIndex(-1);

            row.cells = null;

            foreach (DataGridViewCell cell in Cells)
            {
                row.Cells.Add(cell.Clone() as DataGridViewCell);
            }

            row.SetDataGridView(null);

            return(row);
        }
        public virtual void Clear()
        {
            int total = list.Count;

            DataGridView.OnRowsPreRemovedInternal(new DataGridViewRowsRemovedEventArgs(0, total));

            for (int i = 0; i < total; i++)
            {
                DataGridViewRow row = (DataGridViewRow)list[0];
                row.SetIndex(0);

                // We can exit because the NewRow is always last
                if (row.IsNewRow)
                {
                    break;
                }

                row.SetDataGridView(null);
                list.Remove(row);
            }

            DataGridView.OnRowsPostRemovedInternal(new DataGridViewRowsRemovedEventArgs(0, total));
            OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Refresh, null));
        }
예제 #7
0
		// FIXME: Do *not* allow insertation *after* the editing row!
		public virtual void Insert (int rowIndex, DataGridViewRow dataGridViewRow)
		{
			dataGridViewRow.SetIndex (rowIndex);
			dataGridViewRow.SetDataGridView (dataGridView);
			CompleteRowCells (dataGridViewRow);
			list.Insert (rowIndex, dataGridViewRow);
			ReIndex ();
			OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, dataGridViewRow));
			if (raiseEvent)
				DataGridView.OnRowsAddedInternal (new DataGridViewRowsAddedEventArgs (rowIndex, 1));
		}
예제 #8
0
		private int AddCore (DataGridViewRow dataGridViewRow, bool sharable)
		{
			if (dataGridView.Columns.Count == 0)
				throw new InvalidOperationException ("DataGridView has no columns.");
			
			int result;
			
			dataGridViewRow.SetDataGridView (dataGridView);

			// 
			// Add the row just before the editing row (if there is an editing row).
			// 
			int editing_index = -1;
			if (DataGridView != null && DataGridView.EditingRow != null && DataGridView.EditingRow != dataGridViewRow) {
				editing_index = list.Count - 1; // always the last row
				DataGridView.EditingRow.SetIndex (list.Count);
			}
			
			if (editing_index >= 0) {
				list.Insert (editing_index, dataGridViewRow);
				result = editing_index;
			} else {
				result = list.Add (dataGridViewRow);
			}
			
			if (sharable && CanBeShared (dataGridViewRow)) {
				dataGridViewRow.SetIndex (-1);
			} else {
				dataGridViewRow.SetIndex (result);
			}

			CompleteRowCells (dataGridViewRow);
			for (int i = 0; i < dataGridViewRow.Cells.Count; i++) {
				dataGridViewRow.Cells [i].SetOwningColumn (dataGridView.Columns [i]);
			}

			if (raiseEvent) {
				OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, dataGridViewRow));
				DataGridView.OnRowsAddedInternal (new DataGridViewRowsAddedEventArgs (result, 1));
			}

			return result;
		}