dataview sorting problem -

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jwedel_stolo

    #1

    dataview sorting problem -

    Hi
    I'm creating a dataview "on the fly" in order to sort some data prior to writing out the information to a MS SQL table
    I have used two methods in order to determine the sort order of the DataView. (I'm writing in C# with the v1.1.4322 of the .NET Framework, in Window2K server"). First of all, here are the two methods I have used in order to apply the sorting property to the DataView

    1. Simply defining the sort order and colum
    DataView dvReturn

    string szSort = "DataRowID" + " ASC"
    vReturn.Sort = szSort

    2. Defining a primary key and then setting the default sort order
    propert
    /// when creating the datatable firs
    DataTable dt
    dt.PrimaryKey = new DataColumn[] {dt.Columns["DataRowID"]}
    DataView dvFinal = new DataView(dt)

    // then set the propert
    dvFinal.ApplyDe faultSort = true

    When I attempt to access the data from the DataView, the information is still listed as if it hasn't been sorted. Here is a sample of the code I have implemented in order to retrieve the sorted information (dvReturn would be the DataView I applied the sorting properties to

    int iRowID = System.Convert. ToInt32(dvRetur n[j]["DataRowID"].ToString())
    int iEmpStatusID = System.Convert. ToInt32(dvRetur n[j]["EmpStatusTypeI D"].ToString())

    Any help would be greatly appreciated, as it is not obvious to me what I am doing wrong. Thank you in advance

    jwede



  • William Ryan  eMVP

    #2
    Re: dataview sorting problem -

    Jwedel:

    If you call ApplyDefaultSor t after the sort, it will undo the sort you
    specified and use the original one. What exactly is that last reference
    doing? It looks like you are just referencing one row, so whatever J is
    will determine the sort order. Nonetheless, if you just use Sort like you
    did in the first one, regardless of primary key, you'll sort on that field.
    "jwedel_sto lo" <anonymous@disc ussions.microso ft.com> wrote in message
    news:F0E8F4AB-964B-4286-93B8-FA141364F760@mi crosoft.com...[color=blue]
    > Hi,
    > I'm creating a dataview "on the fly" in order to sort some data prior[/color]
    to writing out the information to a MS SQL table.[color=blue]
    > I have used two methods in order to determine the sort order of the[/color]
    DataView. (I'm writing in C# with the v1.1.4322 of the .NET Framework, in
    Window2K server"). First of all, here are the two methods I have used in
    order to apply the sorting property to the DataView.[color=blue]
    >
    > 1. Simply defining the sort order and column
    > DataView dvReturn;
    >
    > string szSort = "DataRowID" + " ASC";
    > vReturn.Sort = szSort;
    >
    > 2. Defining a primary key and then setting[/color]
    the default sort order[color=blue]
    > property
    > /// when creating the datatable first
    > DataTable dt;
    > dt.PrimaryKey = new DataColumn[][/color]
    {dt.Columns["DataRowID"]};[color=blue]
    > DataView dvFinal = new DataView(dt);
    >
    > // then set the property
    > dvFinal.ApplyDe faultSort = true;
    >
    > When I attempt to access the data from the DataView, the information[/color]
    is still listed as if it hasn't been sorted. Here is a sample of the code I
    have implemented in order to retrieve the sorted information (dvReturn would
    be the DataView I applied the sorting properties to)[color=blue]
    >
    > int iRowID = System.Convert. ToInt32(dvRetur n[j]["DataRowID"].ToString());
    > int iEmpStatusID =[/color]
    System.Convert. ToInt32(dvRetur n[j]["EmpStatusTypeI D"].ToString());[color=blue]
    >
    > Any help would be greatly appreciated, as it is not obvious to me what[/color]
    I am doing wrong. Thank you in advance.[color=blue]
    >
    > jwedel
    >
    >
    >
    >
    >[/color]


    Comment

    • William Ryan  eMVP

      #3
      Re: dataview sorting problem -

      Jwedel:

      If you call ApplyDefaultSor t after the sort, it will undo the sort you
      specified and use the original one. What exactly is that last reference
      doing? It looks like you are just referencing one row, so whatever J is
      will determine the sort order. Nonetheless, if you just use Sort like you
      did in the first one, regardless of primary key, you'll sort on that field.
      "jwedel_sto lo" <anonymous@disc ussions.microso ft.com> wrote in message
      news:F0E8F4AB-964B-4286-93B8-FA141364F760@mi crosoft.com...[color=blue]
      > Hi,
      > I'm creating a dataview "on the fly" in order to sort some data prior[/color]
      to writing out the information to a MS SQL table.[color=blue]
      > I have used two methods in order to determine the sort order of the[/color]
      DataView. (I'm writing in C# with the v1.1.4322 of the .NET Framework, in
      Window2K server"). First of all, here are the two methods I have used in
      order to apply the sorting property to the DataView.[color=blue]
      >
      > 1. Simply defining the sort order and column
      > DataView dvReturn;
      >
      > string szSort = "DataRowID" + " ASC";
      > vReturn.Sort = szSort;
      >
      > 2. Defining a primary key and then setting[/color]
      the default sort order[color=blue]
      > property
      > /// when creating the datatable first
      > DataTable dt;
      > dt.PrimaryKey = new DataColumn[][/color]
      {dt.Columns["DataRowID"]};[color=blue]
      > DataView dvFinal = new DataView(dt);
      >
      > // then set the property
      > dvFinal.ApplyDe faultSort = true;
      >
      > When I attempt to access the data from the DataView, the information[/color]
      is still listed as if it hasn't been sorted. Here is a sample of the code I
      have implemented in order to retrieve the sorted information (dvReturn would
      be the DataView I applied the sorting properties to)[color=blue]
      >
      > int iRowID = System.Convert. ToInt32(dvRetur n[j]["DataRowID"].ToString());
      > int iEmpStatusID =[/color]
      System.Convert. ToInt32(dvRetur n[j]["EmpStatusTypeI D"].ToString());[color=blue]
      >
      > Any help would be greatly appreciated, as it is not obvious to me what[/color]
      I am doing wrong. Thank you in advance.[color=blue]
      >
      > jwedel
      >
      >
      >
      >
      >[/color]


      Comment

      • jwedel_stolo

        #4
        Re: dataview sorting problem -

        William
        1. Apologies for the ambiguity.... I have not used the two sorting mechanisms concurrently. I am aware if you set the sort order initially (as in item #1) and then set the "ApplyDefaultSo rt" property to "true", that it will overwrite the inital sort ou specificed.... (it is clearly stated in the documentation). .. but thank you anyway

        2. The last reference (int iRowID = System.Convert. ToInt32(dvRetur n[j]["DataRowID"].ToString()) is referencing a single row, where "j" is simply an iterator within a "for" loop. I am copying the contents of each row within the DataView back to an ArrayList.

        I am interested in your comment re: "j" though... how will "j" determine my sort order... ?? Please respond at your convenience, and thank you for the assistance

        Regards
        jwede


        ----- William Ryan eMVP wrote: ----

        Jwedel

        If you call ApplyDefaultSor t after the sort, it will undo the sort yo
        specified and use the original one. What exactly is that last referenc
        doing? It looks like you are just referencing one row, so whatever J i
        will determine the sort order. Nonetheless, if you just use Sort like yo
        did in the first one, regardless of primary key, you'll sort on that field
        "jwedel_sto lo" <anonymous@disc ussions.microso ft.com> wrote in messag
        news:F0E8F4AB-964B-4286-93B8-FA141364F760@mi crosoft.com..[color=blue]
        > Hi
        > I'm creating a dataview "on the fly" in order to sort some data prio[/color]
        to writing out the information to a MS SQL table[color=blue]
        > I have used two methods in order to determine the sort order of th[/color]
        DataView. (I'm writing in C# with the v1.1.4322 of the .NET Framework, i
        Window2K server"). First of all, here are the two methods I have used i
        order to apply the sorting property to the DataView[color=blue][color=green]
        >> 1. Simply defining the sort order and colum[/color]
        > DataView dvReturn[color=green]
        >> string szSort = "DataRowID" + " ASC"[/color]
        > vReturn.Sort = szSort[color=green]
        >> 2. Defining a primary key and then settin[/color][/color]
        the default sort orde[color=blue]
        > propert
        > /// when creating the datatable firs
        > DataTable dt
        > dt.PrimaryKey = new DataColumn[[/color]
        {dt.Columns["DataRowID"]}[color=blue]
        > DataView dvFinal = new DataView(dt)[color=green]
        >> // then set the propert[/color]
        > dvFinal.ApplyDe faultSort = true[color=green]
        >> When I attempt to access the data from the DataView, the informatio[/color][/color]
        is still listed as if it hasn't been sorted. Here is a sample of the code
        have implemented in order to retrieve the sorted information (dvReturn woul
        be the DataView I applied the sorting properties to[color=blue][color=green]
        >> int iRowID = System.Convert. ToInt32(dvRetur n[j]["DataRowID"].ToString())[/color]
        > int iEmpStatusID[/color]
        System.Convert. ToInt32(dvRetur n[j]["EmpStatusTypeI D"].ToString())[color=blue][color=green]
        >> Any help would be greatly appreciated, as it is not obvious to me wha[/color][/color]
        I am doing wrong. Thank you in advance[color=blue][color=green]
        >> jwede[color=darkred]
        >>>>>[/color][/color][/color]

        Comment

        • jwedel_stolo

          #5
          Re: dataview sorting problem -

          William
          1. Apologies for the ambiguity.... I have not used the two sorting mechanisms concurrently. I am aware if you set the sort order initially (as in item #1) and then set the "ApplyDefaultSo rt" property to "true", that it will overwrite the inital sort ou specificed.... (it is clearly stated in the documentation). .. but thank you anyway

          2. The last reference (int iRowID = System.Convert. ToInt32(dvRetur n[j]["DataRowID"].ToString()) is referencing a single row, where "j" is simply an iterator within a "for" loop. I am copying the contents of each row within the DataView back to an ArrayList.

          I am interested in your comment re: "j" though... how will "j" determine my sort order... ?? Please respond at your convenience, and thank you for the assistance

          Regards
          jwede


          ----- William Ryan eMVP wrote: ----

          Jwedel

          If you call ApplyDefaultSor t after the sort, it will undo the sort yo
          specified and use the original one. What exactly is that last referenc
          doing? It looks like you are just referencing one row, so whatever J i
          will determine the sort order. Nonetheless, if you just use Sort like yo
          did in the first one, regardless of primary key, you'll sort on that field
          "jwedel_sto lo" <anonymous@disc ussions.microso ft.com> wrote in messag
          news:F0E8F4AB-964B-4286-93B8-FA141364F760@mi crosoft.com..[color=blue]
          > Hi
          > I'm creating a dataview "on the fly" in order to sort some data prio[/color]
          to writing out the information to a MS SQL table[color=blue]
          > I have used two methods in order to determine the sort order of th[/color]
          DataView. (I'm writing in C# with the v1.1.4322 of the .NET Framework, i
          Window2K server"). First of all, here are the two methods I have used i
          order to apply the sorting property to the DataView[color=blue][color=green]
          >> 1. Simply defining the sort order and colum[/color]
          > DataView dvReturn[color=green]
          >> string szSort = "DataRowID" + " ASC"[/color]
          > vReturn.Sort = szSort[color=green]
          >> 2. Defining a primary key and then settin[/color][/color]
          the default sort orde[color=blue]
          > propert
          > /// when creating the datatable firs
          > DataTable dt
          > dt.PrimaryKey = new DataColumn[[/color]
          {dt.Columns["DataRowID"]}[color=blue]
          > DataView dvFinal = new DataView(dt)[color=green]
          >> // then set the propert[/color]
          > dvFinal.ApplyDe faultSort = true[color=green]
          >> When I attempt to access the data from the DataView, the informatio[/color][/color]
          is still listed as if it hasn't been sorted. Here is a sample of the code
          have implemented in order to retrieve the sorted information (dvReturn woul
          be the DataView I applied the sorting properties to[color=blue][color=green]
          >> int iRowID = System.Convert. ToInt32(dvRetur n[j]["DataRowID"].ToString())[/color]
          > int iEmpStatusID[/color]
          System.Convert. ToInt32(dvRetur n[j]["EmpStatusTypeI D"].ToString())[color=blue][color=green]
          >> Any help would be greatly appreciated, as it is not obvious to me wha[/color][/color]
          I am doing wrong. Thank you in advance[color=blue][color=green]
          >> jwede[color=darkred]
          >>>>>[/color][/color][/color]

          Comment

          • William Ryan eMVP

            #6
            Re: dataview sorting problem -



            "jwedel_sto lo" <anonymous@disc ussions.microso ft.com> wrote in message
            news:09F5CB95-331E-45C8-B759-46C16A3F24FA@mi crosoft.com...[color=blue]
            > William,
            > 1. Apologies for the ambiguity.... I have not used the two sorting[/color]
            mechanisms concurrently. I am aware if you set the sort order initially (as
            in item #1) and then set the "ApplyDefaultSo rt" property to "true", that it
            will overwrite the inital sort ou specificed.... (it is clearly stated in
            the documentation). .. but thank you anyway.

            I'm lost then, how does it fit in here or is just extraneous code? When
            does it get applied b/c the timing of the events with this could easily
            explain the problem.[color=blue]
            >
            > 2. The last reference (int iRowID =[/color]
            System.Convert. ToInt32(dvRetur n[j]["DataRowID"].ToString()) is referencing a
            single row, where "j" is simply an iterator within a "for" loop. I am
            copying the contents of each row within the DataView back to an ArrayList..

            We need to determine where exactly the problem is. So go ahead and grab the
            last value of the datatable in Column0 for instance and see what it is.
            Then apply the sort and reference that row within the View! Only the view
            is sorted not the datatable. An easy way to do this is make a test grid and
            bind to it. Have a button that changes the sort field. Click on it a few
            times and make sure it's sorting correctly. You'll have a visual cue if you
            use a grid. I've never seen this not work and I use it constantly so I
            suspect it may appear that it's not sorting but it's probably the reference
            to the row.
            [color=blue]
            >
            > I am interested in your comment re: "j" though... how will "j"[/color]
            determine my sort order... ?? Please respond at your convenience, and thank
            you for the assistance.

            Whatever j will pass that row regardless of how it's sorted. Basically, if
            J is 200 and there are 200 rows, you'll get the last row, but after a sort,
            if the same row is now position 15, it's only going to be 'correct' when j
            is 15.[color=blue]
            >
            > Regards,
            > jwedel
            >
            >
            >
            > ----- William Ryan eMVP wrote: -----
            >
            > Jwedel:
            >
            > If you call ApplyDefaultSor t after the sort, it will undo the sort[/color]
            you[color=blue]
            > specified and use the original one. What exactly is that last[/color]
            reference[color=blue]
            > doing? It looks like you are just referencing one row, so whatever J[/color]
            is[color=blue]
            > will determine the sort order. Nonetheless, if you just use Sort like[/color]
            you[color=blue]
            > did in the first one, regardless of primary key, you'll sort on that[/color]
            field.[color=blue]
            > "jwedel_sto lo" <anonymous@disc ussions.microso ft.com> wrote in message
            > news:F0E8F4AB-964B-4286-93B8-FA141364F760@mi crosoft.com...[color=green]
            > > Hi,
            > > I'm creating a dataview "on the fly" in order to sort some data[/color][/color]
            prior[color=blue]
            > to writing out the information to a MS SQL table.[color=green]
            > > I have used two methods in order to determine the sort order of the[/color]
            > DataView. (I'm writing in C# with the v1.1.4322 of the .NET[/color]
            Framework, in[color=blue]
            > Window2K server"). First of all, here are the two methods I have used[/color]
            in[color=blue]
            > order to apply the sorting property to the DataView.[color=green][color=darkred]
            > >> 1. Simply defining the sort order[/color][/color][/color]
            and column[color=blue][color=green]
            > > DataView dvReturn;[color=darkred]
            > >> string szSort = "DataRowID" + " ASC";[/color]
            > > vReturn.Sort = szSort;[color=darkred]
            > >> 2. Defining a primary key and then[/color][/color][/color]
            setting[color=blue]
            > the default sort order[color=green]
            > > property
            > > /// when creating the datatable[/color][/color]
            first[color=blue][color=green]
            > > DataTable dt;
            > > dt.PrimaryKey = new DataColumn[][/color]
            > {dt.Columns["DataRowID"]};[color=green]
            > > DataView dvFinal = new DataView(dt);[color=darkred]
            > >> // then set the property[/color]
            > > dvFinal.ApplyDe faultSort = true;[color=darkred]
            > >> When I attempt to access the data from the DataView, the[/color][/color][/color]
            information[color=blue]
            > is still listed as if it hasn't been sorted. Here is a sample of the[/color]
            code I[color=blue]
            > have implemented in order to retrieve the sorted information[/color]
            (dvReturn would[color=blue]
            > be the DataView I applied the sorting properties to)[color=green][color=darkred]
            > >> int iRowID =[/color][/color][/color]
            System.Convert. ToInt32(dvRetur n[j]["DataRowID"].ToString());[color=blue][color=green]
            > > int iEmpStatusID =[/color]
            > System.Convert. ToInt32(dvRetur n[j]["EmpStatusTypeI D"].ToString());[color=green][color=darkred]
            > >> Any help would be greatly appreciated, as it is not obvious to[/color][/color][/color]
            me what[color=blue]
            > I am doing wrong. Thank you in advance.[color=green][color=darkred]
            > >> jwedel
            > >>>>>[/color][/color][/color]


            Comment

            • William Ryan eMVP

              #7
              Re: dataview sorting problem -



              "jwedel_sto lo" <anonymous@disc ussions.microso ft.com> wrote in message
              news:09F5CB95-331E-45C8-B759-46C16A3F24FA@mi crosoft.com...[color=blue]
              > William,
              > 1. Apologies for the ambiguity.... I have not used the two sorting[/color]
              mechanisms concurrently. I am aware if you set the sort order initially (as
              in item #1) and then set the "ApplyDefaultSo rt" property to "true", that it
              will overwrite the inital sort ou specificed.... (it is clearly stated in
              the documentation). .. but thank you anyway.

              I'm lost then, how does it fit in here or is just extraneous code? When
              does it get applied b/c the timing of the events with this could easily
              explain the problem.[color=blue]
              >
              > 2. The last reference (int iRowID =[/color]
              System.Convert. ToInt32(dvRetur n[j]["DataRowID"].ToString()) is referencing a
              single row, where "j" is simply an iterator within a "for" loop. I am
              copying the contents of each row within the DataView back to an ArrayList..

              We need to determine where exactly the problem is. So go ahead and grab the
              last value of the datatable in Column0 for instance and see what it is.
              Then apply the sort and reference that row within the View! Only the view
              is sorted not the datatable. An easy way to do this is make a test grid and
              bind to it. Have a button that changes the sort field. Click on it a few
              times and make sure it's sorting correctly. You'll have a visual cue if you
              use a grid. I've never seen this not work and I use it constantly so I
              suspect it may appear that it's not sorting but it's probably the reference
              to the row.
              [color=blue]
              >
              > I am interested in your comment re: "j" though... how will "j"[/color]
              determine my sort order... ?? Please respond at your convenience, and thank
              you for the assistance.

              Whatever j will pass that row regardless of how it's sorted. Basically, if
              J is 200 and there are 200 rows, you'll get the last row, but after a sort,
              if the same row is now position 15, it's only going to be 'correct' when j
              is 15.[color=blue]
              >
              > Regards,
              > jwedel
              >
              >
              >
              > ----- William Ryan eMVP wrote: -----
              >
              > Jwedel:
              >
              > If you call ApplyDefaultSor t after the sort, it will undo the sort[/color]
              you[color=blue]
              > specified and use the original one. What exactly is that last[/color]
              reference[color=blue]
              > doing? It looks like you are just referencing one row, so whatever J[/color]
              is[color=blue]
              > will determine the sort order. Nonetheless, if you just use Sort like[/color]
              you[color=blue]
              > did in the first one, regardless of primary key, you'll sort on that[/color]
              field.[color=blue]
              > "jwedel_sto lo" <anonymous@disc ussions.microso ft.com> wrote in message
              > news:F0E8F4AB-964B-4286-93B8-FA141364F760@mi crosoft.com...[color=green]
              > > Hi,
              > > I'm creating a dataview "on the fly" in order to sort some data[/color][/color]
              prior[color=blue]
              > to writing out the information to a MS SQL table.[color=green]
              > > I have used two methods in order to determine the sort order of the[/color]
              > DataView. (I'm writing in C# with the v1.1.4322 of the .NET[/color]
              Framework, in[color=blue]
              > Window2K server"). First of all, here are the two methods I have used[/color]
              in[color=blue]
              > order to apply the sorting property to the DataView.[color=green][color=darkred]
              > >> 1. Simply defining the sort order[/color][/color][/color]
              and column[color=blue][color=green]
              > > DataView dvReturn;[color=darkred]
              > >> string szSort = "DataRowID" + " ASC";[/color]
              > > vReturn.Sort = szSort;[color=darkred]
              > >> 2. Defining a primary key and then[/color][/color][/color]
              setting[color=blue]
              > the default sort order[color=green]
              > > property
              > > /// when creating the datatable[/color][/color]
              first[color=blue][color=green]
              > > DataTable dt;
              > > dt.PrimaryKey = new DataColumn[][/color]
              > {dt.Columns["DataRowID"]};[color=green]
              > > DataView dvFinal = new DataView(dt);[color=darkred]
              > >> // then set the property[/color]
              > > dvFinal.ApplyDe faultSort = true;[color=darkred]
              > >> When I attempt to access the data from the DataView, the[/color][/color][/color]
              information[color=blue]
              > is still listed as if it hasn't been sorted. Here is a sample of the[/color]
              code I[color=blue]
              > have implemented in order to retrieve the sorted information[/color]
              (dvReturn would[color=blue]
              > be the DataView I applied the sorting properties to)[color=green][color=darkred]
              > >> int iRowID =[/color][/color][/color]
              System.Convert. ToInt32(dvRetur n[j]["DataRowID"].ToString());[color=blue][color=green]
              > > int iEmpStatusID =[/color]
              > System.Convert. ToInt32(dvRetur n[j]["EmpStatusTypeI D"].ToString());[color=green][color=darkred]
              > >> Any help would be greatly appreciated, as it is not obvious to[/color][/color][/color]
              me what[color=blue]
              > I am doing wrong. Thank you in advance.[color=green][color=darkred]
              > >> jwedel
              > >>>>>[/color][/color][/color]


              Comment

              • jwedel_stolo

                #8
                Re: dataview sorting problem - found the fix

                Willia
                Thanks for all your help. As it turns out, the implementation of the sort and the subsequent accessing of the data is correct. I'm sorting on an integer value. Therefore, if I had an array of integers such as 1,2,13,3... the subsequent sort order will be: 1,13,2,3... I had to preceed the values with a '0' in order to obtain the correct sort order I desired....
                (ie; 01, 02, 03, 13... is the sort order I requried).... apologies for wasting your time

                regards
                jwede

                ...
                Thanks in advance

                ----- William Ryan eMVP wrote: ----



                "jwedel_sto lo" <anonymous@disc ussions.microso ft.com> wrote in messag
                news:09F5CB95-331E-45C8-B759-46C16A3F24FA@mi crosoft.com..[color=blue]
                > William
                > 1. Apologies for the ambiguity.... I have not used the two sortin[/color]
                mechanisms concurrently. I am aware if you set the sort order initially (a
                in item #1) and then set the "ApplyDefaultSo rt" property to "true", that i
                will overwrite the inital sort ou specificed.... (it is clearly stated i
                the documentation). .. but thank you anyway

                I'm lost then, how does it fit in here or is just extraneous code? Whe
                does it get applied b/c the timing of the events with this could easil
                explain the problem[color=blue][color=green]
                >> 2. The last reference (int iRowID[/color][/color]
                System.Convert. ToInt32(dvRetur n[j]["DataRowID"].ToString()) is referencing
                single row, where "j" is simply an iterator within a "for" loop. I a
                copying the contents of each row within the DataView back to an ArrayList.

                We need to determine where exactly the problem is. So go ahead and grab th
                last value of the datatable in Column0 for instance and see what it is
                Then apply the sort and reference that row within the View! Only the vie
                is sorted not the datatable. An easy way to do this is make a test grid an
                bind to it. Have a button that changes the sort field. Click on it a fe
                times and make sure it's sorting correctly. You'll have a visual cue if yo
                use a grid. I've never seen this not work and I use it constantly so
                suspect it may appear that it's not sorting but it's probably the referenc
                to the row
                [color=blue][color=green]
                >> I am interested in your comment re: "j" though... how will "j[/color][/color]
                determine my sort order... ?? Please respond at your convenience, and than
                you for the assistance

                Whatever j will pass that row regardless of how it's sorted. Basically, i
                J is 200 and there are 200 rows, you'll get the last row, but after a sort
                if the same row is now position 15, it's only going to be 'correct' when
                is 15[color=blue][color=green]
                >> Regards[/color]
                > jwede[color=green][color=darkred]
                >>>> ----- William Ryan eMVP wrote: ----[/color]
                >> Jwedel
                >> If you call ApplyDefaultSor t after the sort, it will undo the sor[/color][/color]
                yo[color=blue]
                > specified and use the original one. What exactly is that las[/color]
                referenc[color=blue]
                > doing? It looks like you are just referencing one row, so whatever[/color]
                i[color=blue]
                > will determine the sort order. Nonetheless, if you just use Sort lik[/color]
                yo[color=blue]
                > did in the first one, regardless of primary key, you'll sort on tha[/color]
                field[color=blue]
                > "jwedel_sto lo" <anonymous@disc ussions.microso ft.com> wrote in messag
                > news:F0E8F4AB-964B-4286-93B8-FA141364F760@mi crosoft.com..[color=green]
                >> Hi
                >> I'm creating a dataview "on the fly" in order to sort some dat[/color][/color]
                prio[color=blue]
                > to writing out the information to a MS SQL table[color=green]
                >> I have used two methods in order to determine the sort order of th[/color]
                > DataView. (I'm writing in C# with the v1.1.4322 of the .NE[/color]
                Framework, i[color=blue]
                > Window2K server"). First of all, here are the two methods I have use[/color]
                i[color=blue]
                > order to apply the sorting property to the DataView[color=green][color=darkred]
                >>> 1. Simply defining the sort orde[/color][/color][/color]
                and colum[color=blue][color=green]
                >> DataView dvReturn[color=darkred]
                >>> string szSort = "DataRowID" + " ASC"[/color]
                >> vReturn.Sort = szSort[color=darkred]
                >>> 2. Defining a primary key and then[/color][/color][/color]
                setting[color=blue]
                > the default sort order[color=green]
                >> property
                >> /// when creating the datatable[/color][/color]
                first[color=blue][color=green]
                >> DataTable dt;
                >> dt.PrimaryKey = new DataColumn[][/color]
                > {dt.Columns["DataRowID"]};[color=green]
                >> DataView dvFinal = new DataView(dt);[color=darkred]
                >>> // then set the property[/color]
                >> dvFinal.ApplyDe faultSort = true;[color=darkred]
                >>> When I attempt to access the data from the DataView, the[/color][/color][/color]
                information[color=blue]
                > is still listed as if it hasn't been sorted. Here is a sample of the[/color]
                code I[color=blue]
                > have implemented in order to retrieve the sorted information[/color]
                (dvReturn would[color=blue]
                > be the DataView I applied the sorting properties to)[color=green][color=darkred]
                >>> int iRowID =[/color][/color][/color]
                System.Convert. ToInt32(dvRetur n[j]["DataRowID"].ToString());[color=blue][color=green]
                >> int iEmpStatusID =[/color]
                > System.Convert. ToInt32(dvRetur n[j]["EmpStatusTypeI D"].ToString());[color=green][color=darkred]
                >>> Any help would be greatly appreciated, as it is not obvious to[/color][/color][/color]
                me what[color=blue]
                > I am doing wrong. Thank you in advance.[color=green][color=darkred]
                >>> jwedel
                >>>>>>[/color][/color][/color]

                Comment

                • jwedel_stolo

                  #9
                  Re: dataview sorting problem - found the fix

                  Willia
                  Thanks for all your help. As it turns out, the implementation of the sort and the subsequent accessing of the data is correct. I'm sorting on an integer value. Therefore, if I had an array of integers such as 1,2,13,3... the subsequent sort order will be: 1,13,2,3... I had to preceed the values with a '0' in order to obtain the correct sort order I desired....
                  (ie; 01, 02, 03, 13... is the sort order I requried).... apologies for wasting your time

                  regards
                  jwede

                  ...
                  Thanks in advance

                  ----- William Ryan eMVP wrote: ----



                  "jwedel_sto lo" <anonymous@disc ussions.microso ft.com> wrote in messag
                  news:09F5CB95-331E-45C8-B759-46C16A3F24FA@mi crosoft.com..[color=blue]
                  > William
                  > 1. Apologies for the ambiguity.... I have not used the two sortin[/color]
                  mechanisms concurrently. I am aware if you set the sort order initially (a
                  in item #1) and then set the "ApplyDefaultSo rt" property to "true", that i
                  will overwrite the inital sort ou specificed.... (it is clearly stated i
                  the documentation). .. but thank you anyway

                  I'm lost then, how does it fit in here or is just extraneous code? Whe
                  does it get applied b/c the timing of the events with this could easil
                  explain the problem[color=blue][color=green]
                  >> 2. The last reference (int iRowID[/color][/color]
                  System.Convert. ToInt32(dvRetur n[j]["DataRowID"].ToString()) is referencing
                  single row, where "j" is simply an iterator within a "for" loop. I a
                  copying the contents of each row within the DataView back to an ArrayList.

                  We need to determine where exactly the problem is. So go ahead and grab th
                  last value of the datatable in Column0 for instance and see what it is
                  Then apply the sort and reference that row within the View! Only the vie
                  is sorted not the datatable. An easy way to do this is make a test grid an
                  bind to it. Have a button that changes the sort field. Click on it a fe
                  times and make sure it's sorting correctly. You'll have a visual cue if yo
                  use a grid. I've never seen this not work and I use it constantly so
                  suspect it may appear that it's not sorting but it's probably the referenc
                  to the row
                  [color=blue][color=green]
                  >> I am interested in your comment re: "j" though... how will "j[/color][/color]
                  determine my sort order... ?? Please respond at your convenience, and than
                  you for the assistance

                  Whatever j will pass that row regardless of how it's sorted. Basically, i
                  J is 200 and there are 200 rows, you'll get the last row, but after a sort
                  if the same row is now position 15, it's only going to be 'correct' when
                  is 15[color=blue][color=green]
                  >> Regards[/color]
                  > jwede[color=green][color=darkred]
                  >>>> ----- William Ryan eMVP wrote: ----[/color]
                  >> Jwedel
                  >> If you call ApplyDefaultSor t after the sort, it will undo the sor[/color][/color]
                  yo[color=blue]
                  > specified and use the original one. What exactly is that las[/color]
                  referenc[color=blue]
                  > doing? It looks like you are just referencing one row, so whatever[/color]
                  i[color=blue]
                  > will determine the sort order. Nonetheless, if you just use Sort lik[/color]
                  yo[color=blue]
                  > did in the first one, regardless of primary key, you'll sort on tha[/color]
                  field[color=blue]
                  > "jwedel_sto lo" <anonymous@disc ussions.microso ft.com> wrote in messag
                  > news:F0E8F4AB-964B-4286-93B8-FA141364F760@mi crosoft.com..[color=green]
                  >> Hi
                  >> I'm creating a dataview "on the fly" in order to sort some dat[/color][/color]
                  prio[color=blue]
                  > to writing out the information to a MS SQL table[color=green]
                  >> I have used two methods in order to determine the sort order of th[/color]
                  > DataView. (I'm writing in C# with the v1.1.4322 of the .NE[/color]
                  Framework, i[color=blue]
                  > Window2K server"). First of all, here are the two methods I have use[/color]
                  i[color=blue]
                  > order to apply the sorting property to the DataView[color=green][color=darkred]
                  >>> 1. Simply defining the sort orde[/color][/color][/color]
                  and colum[color=blue][color=green]
                  >> DataView dvReturn[color=darkred]
                  >>> string szSort = "DataRowID" + " ASC"[/color]
                  >> vReturn.Sort = szSort[color=darkred]
                  >>> 2. Defining a primary key and then[/color][/color][/color]
                  setting[color=blue]
                  > the default sort order[color=green]
                  >> property
                  >> /// when creating the datatable[/color][/color]
                  first[color=blue][color=green]
                  >> DataTable dt;
                  >> dt.PrimaryKey = new DataColumn[][/color]
                  > {dt.Columns["DataRowID"]};[color=green]
                  >> DataView dvFinal = new DataView(dt);[color=darkred]
                  >>> // then set the property[/color]
                  >> dvFinal.ApplyDe faultSort = true;[color=darkred]
                  >>> When I attempt to access the data from the DataView, the[/color][/color][/color]
                  information[color=blue]
                  > is still listed as if it hasn't been sorted. Here is a sample of the[/color]
                  code I[color=blue]
                  > have implemented in order to retrieve the sorted information[/color]
                  (dvReturn would[color=blue]
                  > be the DataView I applied the sorting properties to)[color=green][color=darkred]
                  >>> int iRowID =[/color][/color][/color]
                  System.Convert. ToInt32(dvRetur n[j]["DataRowID"].ToString());[color=blue][color=green]
                  >> int iEmpStatusID =[/color]
                  > System.Convert. ToInt32(dvRetur n[j]["EmpStatusTypeI D"].ToString());[color=green][color=darkred]
                  >>> Any help would be greatly appreciated, as it is not obvious to[/color][/color][/color]
                  me what[color=blue]
                  > I am doing wrong. Thank you in advance.[color=green][color=darkred]
                  >>> jwedel
                  >>>>>>[/color][/color][/color]

                  Comment

                  • William Ryan  eMVP

                    #10
                    Re: dataview sorting problem - found the fix

                    Not a waste of time at all. But that seems weird, what's the datatype of
                    the column, Int? It looks like a string.
                    "jwedel_sto lo" <anonymous@disc ussions.microso ft.com> wrote in message
                    news:031013C8-074E-4C19-86C2-2A4131EA5A2B@mi crosoft.com...[color=blue]
                    > William
                    > Thanks for all your help. As it turns out, the implementation of the[/color]
                    sort and the subsequent accessing of the data is correct. I'm sorting on an
                    integer value. Therefore, if I had an array of integers such as 1,2,13,3...
                    the subsequent sort order will be: 1,13,2,3... I had to preceed the values
                    with a '0' in order to obtain the correct sort order I desired.....[color=blue]
                    > (ie; 01, 02, 03, 13... is the sort order I requried).... apologies for[/color]
                    wasting your time.[color=blue]
                    >
                    > regards,
                    > jwedel
                    >
                    > ...
                    > Thanks in advance.
                    >
                    > ----- William Ryan eMVP wrote: -----
                    >
                    >
                    >
                    > "jwedel_sto lo" <anonymous@disc ussions.microso ft.com> wrote in message
                    > news:09F5CB95-331E-45C8-B759-46C16A3F24FA@mi crosoft.com...[color=green]
                    > > William,
                    > > 1. Apologies for the ambiguity.... I have not used the two[/color][/color]
                    sorting[color=blue]
                    > mechanisms concurrently. I am aware if you set the sort order[/color]
                    initially (as[color=blue]
                    > in item #1) and then set the "ApplyDefaultSo rt" property to "true",[/color]
                    that it[color=blue]
                    > will overwrite the inital sort ou specificed.... (it is clearly[/color]
                    stated in[color=blue]
                    > the documentation). .. but thank you anyway.
                    >
                    > I'm lost then, how does it fit in here or is just extraneous code?[/color]
                    When[color=blue]
                    > does it get applied b/c the timing of the events with this could[/color]
                    easily[color=blue]
                    > explain the problem.[color=green][color=darkred]
                    > >> 2. The last reference (int iRowID =[/color][/color]
                    > System.Convert. ToInt32(dvRetur n[j]["DataRowID"].ToString()) is[/color]
                    referencing a[color=blue]
                    > single row, where "j" is simply an iterator within a "for" loop. I am
                    > copying the contents of each row within the DataView back to an[/color]
                    ArrayList..[color=blue]
                    >
                    > We need to determine where exactly the problem is. So go ahead and[/color]
                    grab the[color=blue]
                    > last value of the datatable in Column0 for instance and see what it[/color]
                    is.[color=blue]
                    > Then apply the sort and reference that row within the View! Only the[/color]
                    view[color=blue]
                    > is sorted not the datatable. An easy way to do this is make a test[/color]
                    grid and[color=blue]
                    > bind to it. Have a button that changes the sort field. Click on it a[/color]
                    few[color=blue]
                    > times and make sure it's sorting correctly. You'll have a visual cue[/color]
                    if you[color=blue]
                    > use a grid. I've never seen this not work and I use it constantly so[/color]
                    I[color=blue]
                    > suspect it may appear that it's not sorting but it's probably the[/color]
                    reference[color=blue]
                    > to the row.
                    >[color=green][color=darkred]
                    > >> I am interested in your comment re: "j" though... how will "j"[/color][/color]
                    > determine my sort order... ?? Please respond at your convenience, and[/color]
                    thank[color=blue]
                    > you for the assistance.
                    >
                    > Whatever j will pass that row regardless of how it's sorted.[/color]
                    Basically, if[color=blue]
                    > J is 200 and there are 200 rows, you'll get the last row, but after a[/color]
                    sort,[color=blue]
                    > if the same row is now position 15, it's only going to be 'correct'[/color]
                    when j[color=blue]
                    > is 15.[color=green][color=darkred]
                    > >> Regards,[/color]
                    > > jwedel[color=darkred]
                    > >>>> ----- William Ryan eMVP wrote: -----
                    > >> Jwedel:
                    > >> If you call ApplyDefaultSor t after the sort, it will undo the[/color][/color][/color]
                    sort[color=blue]
                    > you[color=green]
                    > > specified and use the original one. What exactly is that last[/color]
                    > reference[color=green]
                    > > doing? It looks like you are just referencing one row, so[/color][/color]
                    whatever J[color=blue]
                    > is[color=green]
                    > > will determine the sort order. Nonetheless, if you just use[/color][/color]
                    Sort like[color=blue]
                    > you[color=green]
                    > > did in the first one, regardless of primary key, you'll sort[/color][/color]
                    on that[color=blue]
                    > field.[color=green]
                    > > "jwedel_sto lo" <anonymous@disc ussions.microso ft.com> wrote in[/color][/color]
                    message[color=blue][color=green]
                    > > news:F0E8F4AB-964B-4286-93B8-FA141364F760@mi crosoft.com...[color=darkred]
                    > >> Hi,
                    > >> I'm creating a dataview "on the fly" in order to sort some[/color][/color][/color]
                    data[color=blue]
                    > prior[color=green]
                    > > to writing out the information to a MS SQL table.[color=darkred]
                    > >> I have used two methods in order to determine the sort order of[/color][/color][/color]
                    the[color=blue][color=green]
                    > > DataView. (I'm writing in C# with the v1.1.4322 of the .NET[/color]
                    > Framework, in[color=green]
                    > > Window2K server"). First of all, here are the two methods I[/color][/color]
                    have used[color=blue]
                    > in[color=green]
                    > > order to apply the sorting property to the DataView.[color=darkred]
                    > >>> 1. Simply defining the sort order[/color][/color]
                    > and column[color=green][color=darkred]
                    > >> DataView dvReturn;
                    > >>> string szSort = "DataRowID" + " ASC";
                    > >> vReturn.Sort = szSort;
                    > >>> 2. Defining a primary key and then[/color][/color]
                    > setting[color=green]
                    > > the default sort order[color=darkred]
                    > >> property
                    > >> /// when creating the datatable[/color][/color]
                    > first[color=green][color=darkred]
                    > >> DataTable dt;
                    > >> dt.PrimaryKey = new DataColumn[][/color]
                    > > {dt.Columns["DataRowID"]};[color=darkred]
                    > >> DataView dvFinal = new DataView(dt);
                    > >>> // then set the property
                    > >> dvFinal.ApplyDe faultSort = true;
                    > >>> When I attempt to access the data from the DataView, the[/color][/color]
                    > information[color=green]
                    > > is still listed as if it hasn't been sorted. Here is a sample[/color][/color]
                    of the[color=blue]
                    > code I[color=green]
                    > > have implemented in order to retrieve the sorted information[/color]
                    > (dvReturn would[color=green]
                    > > be the DataView I applied the sorting properties to)[color=darkred]
                    > >>> int iRowID =[/color][/color]
                    > System.Convert. ToInt32(dvRetur n[j]["DataRowID"].ToString());[color=green][color=darkred]
                    > >> int iEmpStatusID =[/color]
                    > >[/color][/color]
                    System.Convert. ToInt32(dvRetur n[j]["EmpStatusTypeI D"].ToString());[color=blue][color=green][color=darkred]
                    > >>> Any help would be greatly appreciated, as it is not obvious[/color][/color][/color]
                    to[color=blue]
                    > me what[color=green]
                    > > I am doing wrong. Thank you in advance.[color=darkred]
                    > >>> jwedel
                    > >>>>>>[/color][/color][/color]


                    Comment

                    Working...