public Row InsertRow(Row parent, int position, IDictionary <Column, object> initialData = null) { if (parent == null) { throw new ArgumentNullException(nameof(parent)); } if (position < 0 || position > parent.Children.Count) { throw new ArgumentOutOfRangeException(); } var row = new Row { ParentRow = parent }; parent._children.Insert(0, row); //todo unit test data assignment here foreach (var col in Columns) { if (initialData != null && initialData.TryGetValue(col, out var initialValue)) { row.RowValues[col] = initialValue; } else { row.RowValues[col] = col.DefaultValue; } } RowAdded?.Invoke(this, new RowAddedEventArgs(row, position)); return(row); }
public void AlignToRows(IEnumerable <ICell> cells, int spacing, float rowSize) { this.Reset(); int currentRowSize = 0; int skippedEntries = 0; int cellsCounter = 0; foreach (var cell in cells) { currentRowSize += ((int)characterMeasurer(cell.Content).X + spacing); if (currentRowSize > rowSize) { cellsCounter++; var row = new Row(rows.Count, cells.Skip(skippedEntries).Take(cellsCounter - skippedEntries)); rows.Add(row); skippedEntries = cellsCounter; currentRowSize = 0; RowAdded.RaiseEvent(this, new CellAlignerEventArgs(row, rows.Count - 1)); } else { cellsCounter++; } } //add the remaining cells if (cellsCounter - skippedEntries >= 0) { var row = new Row(rows.Count, cells.Skip(skippedEntries).Take(cellsCounter - skippedEntries)); rows.Add(row); RowAdded.RaiseEvent(this, new CellAlignerEventArgs(row, rows.Count - 1)); } }
///<summary>Raises the RowAdded event.</summary> ///<param name="e">A RowEventArgs object that provides the event data.</param> protected virtual void OnRowAdded(RowListEventArgs e) { EventSequence.Execute(() => RowAdded?.Invoke(this, e)); }
protected virtual void OnRowAdded(EventArgs e) { RowAdded?.Invoke(this, e); }
protected override void OnRowAdded(RowListEventArgs e) { base.OnRowAdded(e); EventSequence.Execute(() => RowAdded?.Invoke(this, new RowListEventArgs <TRow>((TRow)e.Row, e.Index))); }
/// <summary> /// Raise the RowAdded event /// </summary> /// <param name="newRow"></param> protected virtual void OnRowAdded(int newRow) { RowAdded?.Invoke(this, newRow); }
protected void ProcessChanges(IReadOnlyCollection <RowChangeBase> changes) { if (this._dataTable == null) { return; } IReadOnlyList <DataRow> wrapper = new ReadOnlyDataRowCollectionWrapper(this._dataTable.Rows); decimal pnl = this._pnl; foreach (RowChangeBase rowChange in changes) { if (rowChange.ChangeType == RowChangeType.Added) { DataRow dataRow = this._dataTable.NewRow(); RowAdded rowAdded = (RowAdded)rowChange; for (int index = 0; index < rowAdded.Data.Length; index++) { object value = rowAdded.Data[index]; if (value == null || value == DBNull.Value) { continue; } DataColumn column = this._dataTable.Columns[index]; if (!column.DataType.IsInstanceOfType(value)) { rowAdded.Data[index] = Convert.ChangeType(value, column.DataType); } } dataRow.ItemArray = rowAdded.Data; this._dataTable.Rows.InsertAt(dataRow, ~wrapper.BinarySearchByValue((string)rowChange.RowKey, row => row.Field <string>("Ticker"))); pnl += dataRow.Field <decimal>("Pnl"); } else { DataRow dataRow = this._dataTable.Rows.Find(rowChange.RowKey); decimal rowPnl = dataRow.Field <decimal>("Pnl"); if (rowChange.ChangeType == RowChangeType.Removed) { dataRow.Delete(); pnl -= rowPnl; } else { foreach (ColumnChange columnChange in ((RowColumnsChanged)rowChange).ColumnChanges) { DataColumn column = this._dataTable.Columns[columnChange.ColumnOrdinal]; if (columnChange.Value != null && columnChange.Value != DBNull.Value) { if (!column.DataType.IsInstanceOfType(columnChange.Value)) { columnChange.Value = Convert.ChangeType(columnChange.Value, column.DataType); } if (column.ColumnName == "Pnl") { // Delta in Pnl pnl += (decimal)columnChange.Value - rowPnl; } } dataRow[column] = columnChange.Value; } } } } this._dataTable.AcceptChanges(); this.Pnl = pnl; }
public void OnRowAdded(T t) { State = TableState.Changed; RowAdded?.Invoke(this, new RowEventArgs <T>(t)); }