Dataview will not sort

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

    #1

    Dataview will not sort

    I have a dataview in which the sort property will not sort the dataview.
    Here's is a simple scenario similar to what I am doing:

    Class Foo

    Private Function Retrieve() As DataView
    ' Returns a DataView with 2 columns and 3 rows
    Dim ADOHelper As New DAL.ADOHelper
    Return ADOHelper.GetMy Dataview()
    End

    Public Sub ShowDataView()
    Dim dv As DataView = Retrieve()
    ' dv's table has 2 columns, integer called "A" and string called "B"
    ' dv has 3 rows as follows:
    ' 2 "DEF"
    ' 3 "GHI"
    ' 4 "JKL"

    Dim drow As DataRow
    drow = dv.Table.NewRow ()
    drow("A") = 1
    drow("B") = "ABC"
    dv.Table.Rows.A dd(drow)

    ' HERE IS THE PROBLEM. SORT DOES NOT SORT.
    dv.Sort = "A"

    For Each eachRow As DataRow In dv.Table.Rows
    Console.WriteLi ne(String.ConCa t(eachRow.Item( "A").ToString() ,
    " - ", eachRow.Item("B ").ToString ()))
    Next

    End Class

    When calling Foo.ShowDataVie w(), the output will be the following:

    2 - DEF
    3 - GHI
    4 - JKL
    1 - ABC

    Any ideas on why the sort is not working? Is there something else I am
    missing? I've applied sorts to all kinds of dataviews before and never had
    this happen, and I've spent 6 hours trying to figure out why it will not
    work. I've even tried sorting on column "B", and tried sorting DESC on each
    column too. Nothing seems to work.

    Any help is greatly appreciated.

    --

    Raymond Lewallen


  • Cowboy (Gregory A. Beamer) - MVP

    #2
    RE: Dataview will not sort

    The View sort and the "sort" on the table are two different things. Try
    binding the DataView to some control in your application and looking at the
    order rather than looping through the original rows.


    ---

    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    *************** ************
    Think Outside the Box!
    *************** ************

    "Raymond Lewallen" wrote:
    [color=blue]
    > I have a dataview in which the sort property will not sort the dataview.
    > Here's is a simple scenario similar to what I am doing:
    >
    > Class Foo
    >
    > Private Function Retrieve() As DataView
    > ' Returns a DataView with 2 columns and 3 rows
    > Dim ADOHelper As New DAL.ADOHelper
    > Return ADOHelper.GetMy Dataview()
    > End
    >
    > Public Sub ShowDataView()
    > Dim dv As DataView = Retrieve()
    > ' dv's table has 2 columns, integer called "A" and string called "B"
    > ' dv has 3 rows as follows:
    > ' 2 "DEF"
    > ' 3 "GHI"
    > ' 4 "JKL"
    >
    > Dim drow As DataRow
    > drow = dv.Table.NewRow ()
    > drow("A") = 1
    > drow("B") = "ABC"
    > dv.Table.Rows.A dd(drow)
    >
    > ' HERE IS THE PROBLEM. SORT DOES NOT SORT.
    > dv.Sort = "A"
    >
    > For Each eachRow As DataRow In dv.Table.Rows
    > Console.WriteLi ne(String.ConCa t(eachRow.Item( "A").ToString() ,
    > " - ", eachRow.Item("B ").ToString ()))
    > Next
    >
    > End Class
    >
    > When calling Foo.ShowDataVie w(), the output will be the following:
    >
    > 2 - DEF
    > 3 - GHI
    > 4 - JKL
    > 1 - ABC
    >
    > Any ideas on why the sort is not working? Is there something else I am
    > missing? I've applied sorts to all kinds of dataviews before and never had
    > this happen, and I've spent 6 hours trying to figure out why it will not
    > work. I've even tried sorting on column "B", and tried sorting DESC on each
    > column too. Nothing seems to work.
    >
    > Any help is greatly appreciated.
    >
    > --
    >
    > Raymond Lewallen
    >
    >
    >[/color]

    Comment

    • Jim Hughes

      #3
      Re: Dataview will not sort

      It appears that it is not sorted because you are using For Each on the
      DataTable instead of looping through the sorted rows in the DataView by
      index

      Try this instead:
      For i As Integer = 0 To dv.Count - 1

      Dim eachrow As DataRowView = dv.Item(i)

      Console.WriteLi ne(String.Conca t(eachrow.Item( "A").ToString() , " - ",
      eachrow.Item("B ").ToString ()))

      Next



      "Raymond Lewallen" <Raymond.CTR.Le wallen@nospam.f aa.gov> wrote in message
      news:OmODhCcxEH A.3024@TK2MSFTN GP14.phx.gbl...[color=blue]
      >I have a dataview in which the sort property will not sort the dataview.
      > Here's is a simple scenario similar to what I am doing:
      >
      > Class Foo
      >
      > Private Function Retrieve() As DataView
      > ' Returns a DataView with 2 columns and 3 rows
      > Dim ADOHelper As New DAL.ADOHelper
      > Return ADOHelper.GetMy Dataview()
      > End
      >
      > Public Sub ShowDataView()
      > Dim dv As DataView = Retrieve()
      > ' dv's table has 2 columns, integer called "A" and string called "B"
      > ' dv has 3 rows as follows:
      > ' 2 "DEF"
      > ' 3 "GHI"
      > ' 4 "JKL"
      >
      > Dim drow As DataRow
      > drow = dv.Table.NewRow ()
      > drow("A") = 1
      > drow("B") = "ABC"
      > dv.Table.Rows.A dd(drow)
      >
      > ' HERE IS THE PROBLEM. SORT DOES NOT SORT.
      > dv.Sort = "A"
      >
      > For Each eachRow As DataRow In dv.Table.Rows
      > Console.WriteLi ne(String.ConCa t(eachRow.Item( "A").ToString() ,
      > " - ", eachRow.Item("B ").ToString ()))
      > Next
      >
      > End Class
      >
      > When calling Foo.ShowDataVie w(), the output will be the following:
      >
      > 2 - DEF
      > 3 - GHI
      > 4 - JKL
      > 1 - ABC
      >
      > Any ideas on why the sort is not working? Is there something else I am
      > missing? I've applied sorts to all kinds of dataviews before and never
      > had
      > this happen, and I've spent 6 hours trying to figure out why it will not
      > work. I've even tried sorting on column "B", and tried sorting DESC on
      > each
      > column too. Nothing seems to work.
      >
      > Any help is greatly appreciated.
      >
      > --
      >
      > Raymond Lewallen
      >
      >[/color]


      Comment

      • Cor Ligthert

        #4
        Re: Dataview will not sort

        Raymond,

        Does this show it you?

        \\\Using the original table from the dataview
        For Each eachRow As DataRow In dv.Table.Rows
        Console.WriteLi ne(String.Conca t(eachRow.Item( "A").ToString() ,
        "-", eachRow.Item("B ").ToString ()))
        Next
        ///
        \\\Using the dataview
        For Each eachRow As DataRowView In dv
        Console.WriteLi ne(String.Conca t(eachRow.Item( "A").ToString() ,
        "-", eachRow.Item("B ").ToString ()))
        Next
        ///

        Cor

        "Raymond Lewallen" <Raymond.CTR.Le wallen@nospam.f aa.gov>
        [color=blue]
        >I have a dataview in which the sort property will not sort the dataview.
        > Here's is a simple scenario similar to what I am doing:
        >
        > Class Foo
        >
        > Private Function Retrieve() As DataView
        > ' Returns a DataView with 2 columns and 3 rows
        > Dim ADOHelper As New DAL.ADOHelper
        > Return ADOHelper.GetMy Dataview()
        > End
        >
        > Public Sub ShowDataView()
        > Dim dv As DataView = Retrieve()
        > ' dv's table has 2 columns, integer called "A" and string called "B"
        > ' dv has 3 rows as follows:
        > ' 2 "DEF"
        > ' 3 "GHI"
        > ' 4 "JKL"
        >
        > Dim drow As DataRow
        > drow = dv.Table.NewRow ()
        > drow("A") = 1
        > drow("B") = "ABC"
        > dv.Table.Rows.A dd(drow)
        >
        > ' HERE IS THE PROBLEM. SORT DOES NOT SORT.
        > dv.Sort = "A"
        >
        > For Each eachRow As DataRow In dv.Table.Rows
        > Console.WriteLi ne(String.ConCa t(eachRow.Item( "A").ToString() ,
        > " - ", eachRow.Item("B ").ToString ()))
        > Next
        >
        > End Class
        >
        > When calling Foo.ShowDataVie w(), the output will be the following:
        >
        > 2 - DEF
        > 3 - GHI
        > 4 - JKL
        > 1 - ABC
        >
        > Any ideas on why the sort is not working? Is there something else I am
        > missing? I've applied sorts to all kinds of dataviews before and never
        > had
        > this happen, and I've spent 6 hours trying to figure out why it will not
        > work. I've even tried sorting on column "B", and tried sorting DESC on
        > each
        > column too. Nothing seems to work.
        >
        > Any help is greatly appreciated.
        >
        > --
        >
        > Raymond Lewallen
        >
        >[/color]


        Comment

        • Jim Hughes

          #5
          Re: Dataview will not sort

          You could also use:

          Dim iterator As IEnumerator = dv.GetEnumerato r
          While iterator.MoveNe xt

          Dim drv As System.Data.Dat aRowView = CType(iterator. Current,
          System.Data.Dat aRowView)

          Console.WriteLi ne(String.Conca t(drv.Item("A") .ToString(), " - ",
          drv.Item("B").T oString()))

          End While


          "Jim Hughes" <NOSPAMJ3033@Ho tmail.com> wrote in message
          news:%23PwohUcx EHA.1076@TK2MSF TNGP10.phx.gbl. ..[color=blue]
          > It appears that it is not sorted because you are using For Each on the
          > DataTable instead of looping through the sorted rows in the DataView by
          > index
          >
          > Try this instead:
          > For i As Integer = 0 To dv.Count - 1
          >
          > Dim eachrow As DataRowView = dv.Item(i)
          >
          > Console.WriteLi ne(String.Conca t(eachrow.Item( "A").ToString() , " - ",
          > eachrow.Item("B ").ToString ()))
          >
          > Next
          >
          >
          >
          > "Raymond Lewallen" <Raymond.CTR.Le wallen@nospam.f aa.gov> wrote in message
          > news:OmODhCcxEH A.3024@TK2MSFTN GP14.phx.gbl...[color=green]
          >>I have a dataview in which the sort property will not sort the dataview.
          >> Here's is a simple scenario similar to what I am doing:
          >>
          >> Class Foo
          >>
          >> Private Function Retrieve() As DataView
          >> ' Returns a DataView with 2 columns and 3 rows
          >> Dim ADOHelper As New DAL.ADOHelper
          >> Return ADOHelper.GetMy Dataview()
          >> End
          >>
          >> Public Sub ShowDataView()
          >> Dim dv As DataView = Retrieve()
          >> ' dv's table has 2 columns, integer called "A" and string called "B"
          >> ' dv has 3 rows as follows:
          >> ' 2 "DEF"
          >> ' 3 "GHI"
          >> ' 4 "JKL"
          >>
          >> Dim drow As DataRow
          >> drow = dv.Table.NewRow ()
          >> drow("A") = 1
          >> drow("B") = "ABC"
          >> dv.Table.Rows.A dd(drow)
          >>
          >> ' HERE IS THE PROBLEM. SORT DOES NOT SORT.
          >> dv.Sort = "A"
          >>
          >> For Each eachRow As DataRow In dv.Table.Rows
          >> Console.WriteLi ne(String.ConCa t(eachRow.Item( "A").ToString() ,
          >> " - ", eachRow.Item("B ").ToString ()))
          >> Next
          >>
          >> End Class
          >>
          >> When calling Foo.ShowDataVie w(), the output will be the following:
          >>
          >> 2 - DEF
          >> 3 - GHI
          >> 4 - JKL
          >> 1 - ABC
          >>
          >> Any ideas on why the sort is not working? Is there something else I am
          >> missing? I've applied sorts to all kinds of dataviews before and never
          >> had
          >> this happen, and I've spent 6 hours trying to figure out why it will not
          >> work. I've even tried sorting on column "B", and tried sorting DESC on
          >> each
          >> column too. Nothing seems to work.
          >>
          >> Any help is greatly appreciated.
          >>
          >> --
          >>
          >> Raymond Lewallen
          >>
          >>[/color]
          >
          >[/color]


          Comment

          • Raymond Lewallen

            #6
            Re: Dataview will not sort

            The view sort and the sort on the base table are 2 different things, that's
            all binding and looking at it will confirm, and you already told me that's
            the case, and I trust you so no need to see it for myself. I need to know
            the best way to take the sorted dataview and loop through it in sorted form
            so my console.write will output sorted information. How can I get the base
            table sorted? Probably can't. Will I have to do DataView.CopyTo to move
            the contents into an array, sort the array and then pull out the
            information? How are other people solving these issues?

            --

            Raymond Lewallen

            "Cowboy (Gregory A. Beamer) - MVP" <NoSpamMgbworld @comcast.netNoS pamM> wrote
            in message news:AACB4AB1-D7F2-4A0B-949E-AF9CEAA3AA61@mi crosoft.com...[color=blue]
            > The View sort and the "sort" on the table are two different things. Try
            > binding the DataView to some control in your application and looking at[/color]
            the[color=blue]
            > order rather than looping through the original rows.
            >
            >
            > ---
            >
            > Gregory A. Beamer
            > MVP; MCP: +I, SE, SD, DBA
            >
            > *************** ************
            > Think Outside the Box!
            > *************** ************
            >
            > "Raymond Lewallen" wrote:
            >[color=green]
            > > I have a dataview in which the sort property will not sort the dataview.
            > > Here's is a simple scenario similar to what I am doing:
            > >
            > > Class Foo
            > >
            > > Private Function Retrieve() As DataView
            > > ' Returns a DataView with 2 columns and 3 rows
            > > Dim ADOHelper As New DAL.ADOHelper
            > > Return ADOHelper.GetMy Dataview()
            > > End
            > >
            > > Public Sub ShowDataView()
            > > Dim dv As DataView = Retrieve()
            > > ' dv's table has 2 columns, integer called "A" and string called "B"
            > > ' dv has 3 rows as follows:
            > > ' 2 "DEF"
            > > ' 3 "GHI"
            > > ' 4 "JKL"
            > >
            > > Dim drow As DataRow
            > > drow = dv.Table.NewRow ()
            > > drow("A") = 1
            > > drow("B") = "ABC"
            > > dv.Table.Rows.A dd(drow)
            > >
            > > ' HERE IS THE PROBLEM. SORT DOES NOT SORT.
            > > dv.Sort = "A"
            > >
            > > For Each eachRow As DataRow In dv.Table.Rows
            > >[/color][/color]
            Console.WriteLi ne(String.ConCa t(eachRow.Item( "A").ToString() ,[color=blue][color=green]
            > > " - ", eachRow.Item("B ").ToString ()))
            > > Next
            > >
            > > End Class
            > >
            > > When calling Foo.ShowDataVie w(), the output will be the following:
            > >
            > > 2 - DEF
            > > 3 - GHI
            > > 4 - JKL
            > > 1 - ABC
            > >
            > > Any ideas on why the sort is not working? Is there something else I am
            > > missing? I've applied sorts to all kinds of dataviews before and never[/color][/color]
            had[color=blue][color=green]
            > > this happen, and I've spent 6 hours trying to figure out why it will not
            > > work. I've even tried sorting on column "B", and tried sorting DESC on[/color][/color]
            each[color=blue][color=green]
            > > column too. Nothing seems to work.
            > >
            > > Any help is greatly appreciated.
            > >
            > > --
            > >
            > > Raymond Lewallen
            > >
            > >
            > >[/color][/color]


            Comment

            • Raymond Lewallen

              #7
              Re: Dataview will not sort

              That's what I was looking for. Thank you. I'm a library writer and don't
              spend much time on these types that are generally used for controls and GUI.

              --

              Raymond Lewallen


              "Jim Hughes" <NOSPAMJ3033@Ho tmail.com> wrote in message
              news:OrnrZdcxEH A.412@TK2MSFTNG P14.phx.gbl...[color=blue]
              > You could also use:
              >
              > Dim iterator As IEnumerator = dv.GetEnumerato r
              > While iterator.MoveNe xt
              >
              > Dim drv As System.Data.Dat aRowView = CType(iterator. Current,
              > System.Data.Dat aRowView)
              >
              > Console.WriteLi ne(String.Conca t(drv.Item("A") .ToString(), " - ",
              > drv.Item("B").T oString()))
              >
              > End While
              >
              >
              > "Jim Hughes" <NOSPAMJ3033@Ho tmail.com> wrote in message
              > news:%23PwohUcx EHA.1076@TK2MSF TNGP10.phx.gbl. ..[color=green]
              > > It appears that it is not sorted because you are using For Each on the
              > > DataTable instead of looping through the sorted rows in the DataView by
              > > index
              > >
              > > Try this instead:
              > > For i As Integer = 0 To dv.Count - 1
              > >
              > > Dim eachrow As DataRowView = dv.Item(i)
              > >
              > > Console.WriteLi ne(String.Conca t(eachrow.Item( "A").ToString() , " - ",
              > > eachrow.Item("B ").ToString ()))
              > >
              > > Next
              > >
              > >
              > >
              > > "Raymond Lewallen" <Raymond.CTR.Le wallen@nospam.f aa.gov> wrote in[/color][/color]
              message[color=blue][color=green]
              > > news:OmODhCcxEH A.3024@TK2MSFTN GP14.phx.gbl...[color=darkred]
              > >>I have a dataview in which the sort property will not sort the dataview.
              > >> Here's is a simple scenario similar to what I am doing:
              > >>
              > >> Class Foo
              > >>
              > >> Private Function Retrieve() As DataView
              > >> ' Returns a DataView with 2 columns and 3 rows
              > >> Dim ADOHelper As New DAL.ADOHelper
              > >> Return ADOHelper.GetMy Dataview()
              > >> End
              > >>
              > >> Public Sub ShowDataView()
              > >> Dim dv As DataView = Retrieve()
              > >> ' dv's table has 2 columns, integer called "A" and string called "B"
              > >> ' dv has 3 rows as follows:
              > >> ' 2 "DEF"
              > >> ' 3 "GHI"
              > >> ' 4 "JKL"
              > >>
              > >> Dim drow As DataRow
              > >> drow = dv.Table.NewRow ()
              > >> drow("A") = 1
              > >> drow("B") = "ABC"
              > >> dv.Table.Rows.A dd(drow)
              > >>
              > >> ' HERE IS THE PROBLEM. SORT DOES NOT SORT.
              > >> dv.Sort = "A"
              > >>
              > >> For Each eachRow As DataRow In dv.Table.Rows
              > >>[/color][/color][/color]
              Console.WriteLi ne(String.ConCa t(eachRow.Item( "A").ToString() ,[color=blue][color=green][color=darkred]
              > >> " - ", eachRow.Item("B ").ToString ()))
              > >> Next
              > >>
              > >> End Class
              > >>
              > >> When calling Foo.ShowDataVie w(), the output will be the following:
              > >>
              > >> 2 - DEF
              > >> 3 - GHI
              > >> 4 - JKL
              > >> 1 - ABC
              > >>
              > >> Any ideas on why the sort is not working? Is there something else I am
              > >> missing? I've applied sorts to all kinds of dataviews before and never
              > >> had
              > >> this happen, and I've spent 6 hours trying to figure out why it will[/color][/color][/color]
              not[color=blue][color=green][color=darkred]
              > >> work. I've even tried sorting on column "B", and tried sorting DESC on
              > >> each
              > >> column too. Nothing seems to work.
              > >>
              > >> Any help is greatly appreciated.
              > >>
              > >> --
              > >>
              > >> Raymond Lewallen
              > >>
              > >>[/color]
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • Raymond Lewallen

                #8
                Re: Dataview will not sort

                Cor,

                Yes, your solution does work. Thank you for posting it. Sorry to bother
                everyone with what seems to be such a remedial question, but I spend most of
                my time in the database and writing supporting libraries, so using these
                types that are more common to the GUI and used to bind to controls is not
                something I spend much time doing, and DataRowView doesn't come up in very
                easily to find places when looking through the help on dataviews.

                Thanks again to Cowboy, Jim and Cor.

                --

                Raymond Lewallen


                "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
                news:%23$f1Zdcx EHA.4028@TK2MSF TNGP15.phx.gbl. ..[color=blue]
                > Raymond,
                >
                > Does this show it you?
                >
                > \\\Using the original table from the dataview
                > For Each eachRow As DataRow In dv.Table.Rows
                > Console.WriteLi ne(String.Conca t(eachRow.Item( "A").ToString() ,
                > "-", eachRow.Item("B ").ToString ()))
                > Next
                > ///
                > \\\Using the dataview
                > For Each eachRow As DataRowView In dv
                > Console.WriteLi ne(String.Conca t(eachRow.Item( "A").ToString() ,
                > "-", eachRow.Item("B ").ToString ()))
                > Next
                > ///
                >
                > Cor
                >
                > "Raymond Lewallen" <Raymond.CTR.Le wallen@nospam.f aa.gov>
                >[color=green]
                > >I have a dataview in which the sort property will not sort the dataview.
                > > Here's is a simple scenario similar to what I am doing:
                > >
                > > Class Foo
                > >
                > > Private Function Retrieve() As DataView
                > > ' Returns a DataView with 2 columns and 3 rows
                > > Dim ADOHelper As New DAL.ADOHelper
                > > Return ADOHelper.GetMy Dataview()
                > > End
                > >
                > > Public Sub ShowDataView()
                > > Dim dv As DataView = Retrieve()
                > > ' dv's table has 2 columns, integer called "A" and string called "B"
                > > ' dv has 3 rows as follows:
                > > ' 2 "DEF"
                > > ' 3 "GHI"
                > > ' 4 "JKL"
                > >
                > > Dim drow As DataRow
                > > drow = dv.Table.NewRow ()
                > > drow("A") = 1
                > > drow("B") = "ABC"
                > > dv.Table.Rows.A dd(drow)
                > >
                > > ' HERE IS THE PROBLEM. SORT DOES NOT SORT.
                > > dv.Sort = "A"
                > >
                > > For Each eachRow As DataRow In dv.Table.Rows
                > > Console.WriteLi ne(String.ConCa t(eachRow.Item( "A").ToString() ,
                > > " - ", eachRow.Item("B ").ToString ()))
                > > Next
                > >
                > > End Class
                > >
                > > When calling Foo.ShowDataVie w(), the output will be the following:
                > >
                > > 2 - DEF
                > > 3 - GHI
                > > 4 - JKL
                > > 1 - ABC
                > >
                > > Any ideas on why the sort is not working? Is there something else I am
                > > missing? I've applied sorts to all kinds of dataviews before and never
                > > had
                > > this happen, and I've spent 6 hours trying to figure out why it will not
                > > work. I've even tried sorting on column "B", and tried sorting DESC on
                > > each
                > > column too. Nothing seems to work.
                > >
                > > Any help is greatly appreciated.
                > >
                > > --
                > >
                > > Raymond Lewallen
                > >
                > >[/color]
                >
                >[/color]


                Comment

                • Miha Markic [MVP C#]

                  #9
                  Re: Dataview will not sort

                  Hi Raymond,

                  "Raymond Lewallen" <Raymond.CTR.Le wallen@nospam.f aa.gov> wrote in message
                  news:%23OxE7icx EHA.3276@TK2MSF TNGP15.phx.gbl. ..[color=blue]
                  > The view sort and the sort on the base table are 2 different things,
                  > that's
                  > all binding and looking at it will confirm, and you already told me that's
                  > the case, and I trust you so no need to see it for myself. I need to know
                  > the best way to take the sorted dataview and loop through it in sorted
                  > form
                  > so my console.write will output sorted information.[/color]

                  foreach (DataRowView rowView in view)
                  Console.WriteLi ne(rowView["Column"]);

                  How can I get the base[color=blue]
                  > table sorted? Probably can't. Will I have to do DataView.CopyTo to move
                  > the contents into an array, sort the array and then pull out the
                  > information? How are other people solving these issues?[/color]

                  Why do you need to sort table?
                  Why don't you just use DataView?

                  --
                  Miha Markic [MVP C#] - RightHand .NET consulting & development
                  SLODUG - Slovene Developer Users Group

                  [color=blue]
                  >
                  > --
                  >
                  > Raymond Lewallen
                  >
                  > "Cowboy (Gregory A. Beamer) - MVP" <NoSpamMgbworld @comcast.netNoS pamM>
                  > wrote
                  > in message news:AACB4AB1-D7F2-4A0B-949E-AF9CEAA3AA61@mi crosoft.com...[color=green]
                  >> The View sort and the "sort" on the table are two different things. Try
                  >> binding the DataView to some control in your application and looking at[/color]
                  > the[color=green]
                  >> order rather than looping through the original rows.
                  >>
                  >>
                  >> ---
                  >>
                  >> Gregory A. Beamer
                  >> MVP; MCP: +I, SE, SD, DBA
                  >>
                  >> *************** ************
                  >> Think Outside the Box!
                  >> *************** ************
                  >>
                  >> "Raymond Lewallen" wrote:
                  >>[color=darkred]
                  >> > I have a dataview in which the sort property will not sort the
                  >> > dataview.
                  >> > Here's is a simple scenario similar to what I am doing:
                  >> >
                  >> > Class Foo
                  >> >
                  >> > Private Function Retrieve() As DataView
                  >> > ' Returns a DataView with 2 columns and 3 rows
                  >> > Dim ADOHelper As New DAL.ADOHelper
                  >> > Return ADOHelper.GetMy Dataview()
                  >> > End
                  >> >
                  >> > Public Sub ShowDataView()
                  >> > Dim dv As DataView = Retrieve()
                  >> > ' dv's table has 2 columns, integer called "A" and string called
                  >> > "B"
                  >> > ' dv has 3 rows as follows:
                  >> > ' 2 "DEF"
                  >> > ' 3 "GHI"
                  >> > ' 4 "JKL"
                  >> >
                  >> > Dim drow As DataRow
                  >> > drow = dv.Table.NewRow ()
                  >> > drow("A") = 1
                  >> > drow("B") = "ABC"
                  >> > dv.Table.Rows.A dd(drow)
                  >> >
                  >> > ' HERE IS THE PROBLEM. SORT DOES NOT SORT.
                  >> > dv.Sort = "A"
                  >> >
                  >> > For Each eachRow As DataRow In dv.Table.Rows
                  >> >[/color][/color]
                  > Console.WriteLi ne(String.ConCa t(eachRow.Item( "A").ToString() ,[color=green][color=darkred]
                  >> > " - ", eachRow.Item("B ").ToString ()))
                  >> > Next
                  >> >
                  >> > End Class
                  >> >
                  >> > When calling Foo.ShowDataVie w(), the output will be the following:
                  >> >
                  >> > 2 - DEF
                  >> > 3 - GHI
                  >> > 4 - JKL
                  >> > 1 - ABC
                  >> >
                  >> > Any ideas on why the sort is not working? Is there something else I am
                  >> > missing? I've applied sorts to all kinds of dataviews before and never[/color][/color]
                  > had[color=green][color=darkred]
                  >> > this happen, and I've spent 6 hours trying to figure out why it will
                  >> > not
                  >> > work. I've even tried sorting on column "B", and tried sorting DESC on[/color][/color]
                  > each[color=green][color=darkred]
                  >> > column too. Nothing seems to work.
                  >> >
                  >> > Any help is greatly appreciated.
                  >> >
                  >> > --
                  >> >
                  >> > Raymond Lewallen
                  >> >
                  >> >
                  >> >[/color][/color]
                  >
                  >[/color]


                  Comment

                  • Raymond Lewallen

                    #10
                    Re: Dataview will not sort

                    > Why do you need to sort table?

                    I don't now that I know there is a rows collection of sorts for the
                    dataview, i.e. the DataRowView. Thats not something that was easy to find
                    associated with a dataview when looking up dataview and sorting in the help
                    files.
                    [color=blue]
                    > Why don't you just use DataView?[/color]

                    I am now that I have your solution along with Jim's and Cor's.

                    Thank you for posting a solution,

                    --

                    Raymond Lewallen


                    Comment

                    Working...