Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, i have a sorted table with (
C#
dt.DefaultView.Sort = "IndexSubImg 1,Distanta Euclidiana asc";
) sorting method, and i need to get the valuse from the column "Distanta Euclidiana" into an array in sorted order, but when i use the next code i get the array with unsorted order of elements.
C#
public double[] de(DataTable dt)
       {
          double[] d = new double[dt.Rows.Count];

           int i=0;
           foreach (DataRow row in dt.Rows)
           {

               d[i]=(double) row["Distanta Euclidiana"];

           i++;
           }


        return d;
       }

So from what i understand my method of sorting it doesent change the cells from row 9(for example) to row 0 and so on it only moves the row 9 to first pozition (or something like that). How can i make my array to get the elemnts in right position?
Posted

1 solution

change this line
C#
foreach (DataRow row in dt.Rows)

to this
C#
foreach (DataRow row in dt.DefaultView)
 
Share this answer
 
Comments
aryx123 6-Apr-12 13:11pm    
foreach (DataRow row in dt.DefaultView)it gives an error but foreach (DataRowView row in dt.DefaultView) works, thank you for solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900