1

我正在使用下面的代码对我的数据进行排序,程序运行时没有任何问题,但是行中的数据没有被排序..并且找不到会出现这种情况的原因。

DataTable extractedData = new DataTable();
//data added to datatable extractedData
DataView dv = new DataView();
dv =extractedData.AsDataView();
dv.Sort = dv.Table.Columns[10].ColumnName + "  DESC";
extractedData = dv.Table;

下面的apose.slides代码用于将代码添加到演示表中。

 string val = "";
 int col = 0;
 int row = 0;
 for (int i = 1; i < table.Rows.Count; i++)
 {
    for (int j = 0; j < table.Columns.Count; j++)
    {
        if (j == 0)
         {
             val = extractedData.Rows[row][valuesUsed[col]].ToString();
             string[] removeQuestion = val.Split('[', ']');
             val = removeQuestion[1];
         }
         else
         {
             val = extractedData.Rows[row][valuesUsed[col]].ToString();
             if (val == "-" || val == "")
             {
                 val = extractedData.Rows[row][valuesUsed[col]].ToString();
             }
             else
             {
                 val = Convert.ToString(Math.Round(Convert.ToDouble(extractedData.Rows[row][valuesUsed[col]]), MidpointRounding.AwayFromZero));
             }
         }
         table[j, i].TextFrame.Text = val;
         col++;
     }
     row++;
     col = 0;
 }
4

2 回答 2

1

这将起作用:-

DataView dv = extractedData.DefaultView;
dv.Sort = extractedData.Columns[10].ColumnName + "  DESC";

您需要将 DataView 设置为 DataTables 默认视图才能使其正常工作。

这是您也应该查看的链接。

http://msdn.microsoft.com/en-us/library/system.data.dataview.sort.aspx

于 2012-12-07T12:28:14.203 回答
0

将代码的最后一行更改为dv.toTable()而不是dv.Table.

DataTable extractedData = new DataTable();
//data added to datatable extractedData
DataView dv = new DataView();
dv = extractedData.DefaultView;
dv.Sort = "ColumnName  DESC";   //mention exact name of your column
//or else
//dv.Sort = extractedData.Columns[9].ColumnName + "  DESC";
extractedData = dv.toTable();  //Instead of dv.Table;

有关信息,请通过此链接

于 2012-12-07T12:24:51.797 回答