Question

I have a sorted data view. But when I call with the index of rows, it is like not sorted. This is my code:

DataTable dt = inputDataTable.Clone();
for (int i = 0; i < inputDataTable.Columns.Count; i++)
{
    dt.Columns[i].DataType = Type.GetType("System.Double");
}

foreach (DataRow dr in inputDataTable.Rows)
{
    dt.ImportRow(dr);
}
dt.AcceptChanges();

DataView dv = dt.DefaultView;
dv.Sort = dv.Table.Columns[1].ColumnName + " ASC";

when I call it:

dv.Table.Rows[2].ItemArray[2]

I still get the old value (which is not sorted by column number 1). I want to get the new sorted value. How to do that?

Was it helpful?

Solution

Got the answer:

DataView dv = inputDataTable.DefaultView;
dv.Sort = dv.Table.Columns[2].ColumnName + " ASC";
DataTable dT = dv.ToTable();

That code will be make a sorted dataview. Thank you for your answer.

OTHER TIPS

try this :-

dv = dv.Sort = dv.Table.Columns[1].ColumnName + " ASC";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top