Home All Groups Group Topic Archive Search About
Author
19 Sep 2006 7:45 PM
Jim
I have a dataview that I'm trying to apply a sort to, but when I
iterate through the rows in the dataview, they are still in the
original order.  Here's my code.  I'm using an XML document to populate
my DataSet

DataView dvProject = new DataView(MyDS.Tables["Project"], "FY = 2008",
"FY ASC", DataViewRowState.None);
            // dvProject.Sort = "FY ASC, Quarter ASC";
            Console.WriteLine("{0}", dvProject.Sort);

            foreach (DataRow _Project in dvProject.Table.Rows)
            {
                Console.WriteLine("{0}{1}", _Project["FY"], _Project["Quarter"]);
            }

Should be fairly straight-forward right??  I even tried to put on a
rowfilter with no luck.  Anyone have any ideas?  thx --jim

Author
19 Sep 2006 7:59 PM
Marina Levit [MVP]
The rows never physically get sorted. The view provides a sorted view of the
data. The table never changes. You have to access the data through the view
to see it sorted. Going to the table itself does nothing - no reason to
create the view in the first place.

This is why you can have multiple views on one table. Otherwise, which one
would win?

Show quote
"Jim" <keit***@gmail.com> wrote in message
news:1158695140.346936.70610@d34g2000cwd.googlegroups.com...
>I have a dataview that I'm trying to apply a sort to, but when I
> iterate through the rows in the dataview, they are still in the
> original order.  Here's my code.  I'm using an XML document to populate
> my DataSet
>
> DataView dvProject = new DataView(MyDS.Tables["Project"], "FY = 2008",
> "FY ASC", DataViewRowState.None);
> // dvProject.Sort = "FY ASC, Quarter ASC";
> Console.WriteLine("{0}", dvProject.Sort);
>
> foreach (DataRow _Project in dvProject.Table.Rows)
> {
> Console.WriteLine("{0}{1}", _Project["FY"], _Project["Quarter"]);
> }
>
> Should be fairly straight-forward right??  I even tried to put on a
> rowfilter with no luck.  Anyone have any ideas?  thx --jim
>
Author
19 Sep 2006 8:00 PM
Jim Hughes
by using the Table property, you are going "up" a level and ignoring the
DataView completely.

foreach (DataRow _Project in dvProject.Table.Rows)

Instead of using foreach, use a for loop since the order "matters" to you
since you are using a dataview.
DataTable dt = new DataTable();

DataView db = new DataView(dt);

for (int i=0;i<dv.Count;i++)

{

dv[i].

}


Show quote
"Jim" <keit***@gmail.com> wrote in message
news:1158695140.346936.70610@d34g2000cwd.googlegroups.com...
>I have a dataview that I'm trying to apply a sort to, but when I
> iterate through the rows in the dataview, they are still in the
> original order.  Here's my code.  I'm using an XML document to populate
> my DataSet
>
> DataView dvProject = new DataView(MyDS.Tables["Project"], "FY = 2008",
> "FY ASC", DataViewRowState.None);
> // dvProject.Sort = "FY ASC, Quarter ASC";
> Console.WriteLine("{0}", dvProject.Sort);
>
> foreach (DataRow _Project in dvProject.Table.Rows)
> {
> Console.WriteLine("{0}{1}", _Project["FY"], _Project["Quarter"]);
> }
>
> Should be fairly straight-forward right??  I even tried to put on a
> rowfilter with no luck.  Anyone have any ideas?  thx --jim
>
Author
19 Sep 2006 8:16 PM
Jim
Thank everyone.  I didn't realize using the .Table pointed me back to
my original table. I've got it working now.  Much appreciated!!

Jim

Jim Hughes wrote:
Show quote
> by using the Table property, you are going "up" a level and ignoring the
> DataView completely.
>
> foreach (DataRow _Project in dvProject.Table.Rows)
>
> Instead of using foreach, use a for loop since the order "matters" to you
> since you are using a dataview.
> DataTable dt = new DataTable();
>
> DataView db = new DataView(dt);
>
> for (int i=0;i<dv.Count;i++)
>
> {
>
> dv[i].
>
> }
>
>
> "Jim" <keit***@gmail.com> wrote in message
> news:1158695140.346936.70610@d34g2000cwd.googlegroups.com...
> >I have a dataview that I'm trying to apply a sort to, but when I
> > iterate through the rows in the dataview, they are still in the
> > original order.  Here's my code.  I'm using an XML document to populate
> > my DataSet
> >
> > DataView dvProject = new DataView(MyDS.Tables["Project"], "FY = 2008",
> > "FY ASC", DataViewRowState.None);
> > // dvProject.Sort = "FY ASC, Quarter ASC";
> > Console.WriteLine("{0}", dvProject.Sort);
> >
> > foreach (DataRow _Project in dvProject.Table.Rows)
> > {
> > Console.WriteLine("{0}{1}", _Project["FY"], _Project["Quarter"]);
> > }
> >
> > Should be fairly straight-forward right??  I even tried to put on a
> > rowfilter with no luck.  Anyone have any ideas?  thx --jim
> >
Author
19 Sep 2006 8:04 PM
Kerry Moorman
Jim,

Sorting a dataview does not change the order of the rows in the dataview's
underlying table.

You might want to get each datarowview from the dataview. They will be in
sorted order.

Kerry Moorman


Show quote
"Jim" wrote:

> I have a dataview that I'm trying to apply a sort to, but when I
> iterate through the rows in the dataview, they are still in the
> original order.  Here's my code.  I'm using an XML document to populate
> my DataSet
>
> DataView dvProject = new DataView(MyDS.Tables["Project"], "FY = 2008",
> "FY ASC", DataViewRowState.None);
>             // dvProject.Sort = "FY ASC, Quarter ASC";
>             Console.WriteLine("{0}", dvProject.Sort);
>
>             foreach (DataRow _Project in dvProject.Table.Rows)
>             {
>                 Console.WriteLine("{0}{1}", _Project["FY"], _Project["Quarter"]);
>             }
>
> Should be fairly straight-forward right??  I even tried to put on a
> rowfilter with no luck.  Anyone have any ideas?  thx --jim
>
>
Author
20 Sep 2006 3:38 AM
Cor Ligthert [MVP]
Jim,

You can make a (sorted) copy of the table with the in VS 2005 new overloaded
method "ToTable".

http://msdn2.microsoft.com/en-us/library/a8ycds2f.aspx

I hope this helps,

Cor

Show quote
"Jim" <keit***@gmail.com> schreef in bericht
news:1158695140.346936.70610@d34g2000cwd.googlegroups.com...
>I have a dataview that I'm trying to apply a sort to, but when I
> iterate through the rows in the dataview, they are still in the
> original order.  Here's my code.  I'm using an XML document to populate
> my DataSet
>
> DataView dvProject = new DataView(MyDS.Tables["Project"], "FY = 2008",
> "FY ASC", DataViewRowState.None);
> // dvProject.Sort = "FY ASC, Quarter ASC";
> Console.WriteLine("{0}", dvProject.Sort);
>
> foreach (DataRow _Project in dvProject.Table.Rows)
> {
> Console.WriteLine("{0}{1}", _Project["FY"], _Project["Quarter"]);
> }
>
> Should be fairly straight-forward right??  I even tried to put on a
> rowfilter with no luck.  Anyone have any ideas?  thx --jim
>

AddThis Social Bookmark Button