+2009-02-03 Ivan N. Zlatev <contact@i-nz.net>
+
+ * DataGridViewRowCollection.cs, DataGridView.cs: Move row completion
+ code in the row collection code, so that the completion happens before
+ the CollectionChanged event, also better encapsulation.
+ [Fixes bug #471987]
+
2009-02-02 Ivan N. Zlatev <contact@i-nz.net>
* DataGridView.cs: When editing is finished do not remove the editing
if (hover_cell != null && hover_cell.RowIndex >= e.RowIndex)
hover_cell = null;
- // Complete the rows if they are incomplete.
- for (int i = e.RowIndex; i < e.RowIndex + e.RowCount; i++) {
- if (Rows[i].Cells.Count < ColumnCount) {
- for (int j = Rows[i].Cells.Count; j < ColumnCount; j++)
- Rows[i].Cells.Add ((DataGridViewCell) columns[j].CellTemplate.Clone ());
- }
- }
-
AutoResizeColumnsInternal ();
Invalidate ();
OnRowsAdded (e);
dataGridViewRow.SetIndex (result);
}
dataGridViewRow.SetDataGridView (dataGridView);
-
+ CompleteRowCells (dataGridViewRow);
for (int i = 0; i < dataGridViewRow.Cells.Count; i++) {
dataGridViewRow.Cells [i].SetOwningColumn (dataGridView.Columns [i]);
}
return result;
}
+ // Complete the rows if they are incomplete.
+ private void CompleteRowCells (DataGridViewRow row)
+ {
+ if (row == null || DataGridView == null)
+ return;
+
+ if (row.Cells.Count < DataGridView.ColumnCount) {
+ for (int i = row.Cells.Count; i < DataGridView.ColumnCount; i++)
+ row.Cells.Add ((DataGridViewCell) DataGridView.Columns[i].CellTemplate.Clone ());
+ }
+ }
+
public virtual int Add (DataGridViewRow dataGridViewRow)
{
if (dataGridView.DataSource != null)
{
dataGridViewRow.SetIndex (rowIndex);
dataGridViewRow.SetDataGridView (dataGridView);
+ CompleteRowCells (dataGridViewRow);
list[rowIndex] = dataGridViewRow;
OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, dataGridViewRow));
if (raiseEvent)