Skip to content

Commit

Permalink
2010-07-23 Veerapuram Varadhan <v.varadhan@gmail.com>
Browse files Browse the repository at this point in the history
	** Fixes #623451
	* DataColumnCollection.cs (MoveColumn): Fix shifting of
	DataColumn according to the direction of movement.
  • Loading branch information
vvaradhan committed Jul 23, 2010
1 parent ccc84ff commit 4613d59
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
6 changes: 6 additions & 0 deletions mcs/class/System.Data/System.Data/ChangeLog
@@ -1,3 +1,9 @@
2010-07-23 Veerapuram Varadhan <v.varadhan@gmail.com>

** Fixes #623451
* DataColumnCollection.cs (MoveColumn): Fix shifting of DataColumn
according to the direction of movement.

2010-06-23 Veerapuram Varadhan <vvaradhan@novell.com>

** Fixes #581679
Expand Down
9 changes: 8 additions & 1 deletion mcs/class/System.Data/System.Data/DataColumnCollection.cs
Expand Up @@ -714,9 +714,16 @@ internal void MoveColumn (int oldOrdinal, int newOrdinal)
int start = newOrdinal > oldOrdinal ? oldOrdinal : newOrdinal;
int end = newOrdinal > oldOrdinal ? newOrdinal : oldOrdinal;
int direction = newOrdinal > oldOrdinal ? 1 : (-1);

// swap ordinals as per direction of column movement
if (direction < 0) {
start = start + end;
end = start - end;
start -= end;
}

DataColumn currColumn = this [start];
for (int i = start; i < end; i += direction) {
for (int i = start; (direction>0 ? i<end : i>end); i += direction) {
List [i] = List [i+direction];
((DataColumn) List [i]).Ordinal = i;
}
Expand Down
4 changes: 4 additions & 0 deletions mcs/class/System.Data/Test/System.Data/ChangeLog
@@ -1,3 +1,7 @@
2010-07-23 Veerapuram Varadhan <v.varadhan@gmail.com>

* DataColumnTest.cs (B623451_SetOrdinalTest): Added new.

2010-07-23 Veerapuram Varadhan <v.varadhan@gmail.com>

* DataColumnTest.cs (B565616_NonIConvertibleTypeTest): Added new.
Expand Down
26 changes: 26 additions & 0 deletions mcs/class/System.Data/Test/System.Data/DataColumnTest.cs
Expand Up @@ -887,5 +887,31 @@ public void B565616_NonIConvertibleTypeTest ()
Assert.Fail ("#NonIConvertibleType Test");
}
}

[Test]
public void B623451_SetOrdinalTest ()
{
try {
DataTable t = new DataTable();
t.Columns.Add("one");
t.Columns.Add("two");
t.Columns.Add("three");
Assert.AreEqual ("one", t.Columns[0].ColumnName, "#SO1-1");
Assert.AreEqual ("two", t.Columns[1].ColumnName, "#SO1-2");
Assert.AreEqual ("three", t.Columns[2].ColumnName, "#SO1-3");

t.Columns["three"].SetOrdinal(0);
Assert.AreEqual ("three", t.Columns[0].ColumnName, "S02-1");
Assert.AreEqual ("one", t.Columns[1].ColumnName, "S02-2");
Assert.AreEqual ("two", t.Columns[2].ColumnName, "S02-3");

t.Columns["three"].SetOrdinal(1);
Assert.AreEqual ("one", t.Columns[0].ColumnName, "S03-1");
Assert.AreEqual ("three", t.Columns[1].ColumnName, "S03-2");
Assert.AreEqual ("two", t.Columns[2].ColumnName, "S03-3");
} catch (ArgumentOutOfRangeException ex) {
Assert.Fail ("SetOrdinalTest failed");
}
}
}
}

0 comments on commit 4613d59

Please sign in to comment.