Dataview.Sort not working.

This is weird.

I have a DataView that I create from a DataTable like this:

-------------------------------------------------------

DataView masterDv = new DataView(masterTable);

-------------------------------------------------------

Column #12 is called 'CLIENT':

-------------------------------------------------------

masterDv.Table.Columns[12].ColumnName="CLIENT"

-------------------------------------------------------

When I set the sort property of the DataView, the Dataview doesn't change.

masterDv.Sort = "CLIENT";

-------------------------------------------------------

Am i missing something

thanks.

doug



Answer this question

Dataview.Sort not working.

  • Ric Bevan

    Is the DataView set as the default view on the DataTable

    Something like: masterTable.DefaultView = masterDv;

    As far as viewing the sorted DataTable, either the DataView has to be the default view for the DataTable or the DataSource for the control you view the data through has to be masterDv...

    Hope this help If not, could you describe how you are displaying the sorted data


  • Igr Alexánder Fernández Saúco

    I cannot set the DefaultView property on the masterTable. The compiler complains that the property is read only.

    Error 1 Property or indexer 'System.Data.DataTable.DefaultView' cannot be assigned to -- it is read only C:\Documents and Settings\DEXTERDR\My Documents\Visual Studio 2005\Projects\FocusDPE\FocusDPE\FocusDataReader.cs 187 13 FocusDPE

    This is crazy!


  • Mongsreturn

    nope..

    I'm  at a loss..

    I set up a console app just to test and the SAME EXACT functionality is working.

    I just don't get it....

    The context of the sort is within a Custom Data Extension for SQL Server Reporting Services

    Here's my code just in case there's something I missed.

    DataTable masterTable;

    bool Microsoft.ReportingServices.DataProcessing.IDataReader.Read(){
    DataView dv = new DataView(masterTable);
    dv.Sort = "PROJECT";
    int colCounter = 0;
    while (rowCounter < dv.Table.Rows.Count)
    {
     if (dv.Table.Rows != null)
     {

      foreach (DataColumn dc in dv.Table.Columns)

      {

       m_cols[colCounter] = dv.Table.Rows[rowCounter].ItemArray[colCounter].ToString();

       colCounter++;

      }

      rowCounter++;
      return true;
     }
    }
    return false;
    }

    Thanks in advance...

     

    Doug



  • Kirill Tropin

    No problem. I'm sorry I didn't notice that... apply to the sort string to the DataTable.DefaultView.Sort property.

    Let me know if that worked...


  • ElxO

    Hi there,

    I think the problem you are encountering is due to you accessing the wrong "view"...

    Once you have run the sort function you have 2 "views" - the default view, which is accessed by dv.Table and the new (sorted) view... accessed by dv[0]

    Try that - you should find it sorts you out

    Cheers

    Mike


  • Dan10468

    although the sort is suppose to default to ascending have you tried to explicitly state "ASC" and then "DESC" to see if that makes a diff

    masterDv.Sort = "CLIENT ASC";

    masterDv.Sort = "CLIENT DESC";

    HTH



  • SOLIDBOSS

    Did you every figure this out I am facing the same issue.
  • TravisXXX

    no.

    it makes no difference if I stipulate ASC or DESC

    I can't undersand it..

    thanks.


  • Dataview.Sort not working.