472,333 Members | 1,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,333 software developers and data experts.

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.GetMyDataview()
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.Add(drow)

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

For Each eachRow As DataRow In dv.Table.Rows
Console.WriteLine(String.ConCat(eachRow.Item("A"). ToString(),
" - ", eachRow.Item("B").ToString()))
Next

End Class

When calling Foo.ShowDataView(), 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
Jul 21 '05 #1
9 1964
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:
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.GetMyDataview()
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.Add(drow)

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

For Each eachRow As DataRow In dv.Table.Rows
Console.WriteLine(String.ConCat(eachRow.Item("A"). ToString(),
" - ", eachRow.Item("B").ToString()))
Next

End Class

When calling Foo.ShowDataView(), 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

Jul 21 '05 #2
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.WriteLine(String.Concat(eachrow.Item("A"). ToString(), " - ",
eachrow.Item("B").ToString()))

Next

"Raymond Lewallen" <Ra******************@nospam.faa.gov> wrote in message
news:Om**************@TK2MSFTNGP14.phx.gbl...
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.GetMyDataview()
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.Add(drow)

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

For Each eachRow As DataRow In dv.Table.Rows
Console.WriteLine(String.ConCat(eachRow.Item("A"). ToString(),
" - ", eachRow.Item("B").ToString()))
Next

End Class

When calling Foo.ShowDataView(), 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

Jul 21 '05 #3
Raymond,

Does this show it you?

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

Cor

"Raymond Lewallen" <Ra******************@nospam.faa.gov>
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.GetMyDataview()
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.Add(drow)

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

For Each eachRow As DataRow In dv.Table.Rows
Console.WriteLine(String.ConCat(eachRow.Item("A"). ToString(),
" - ", eachRow.Item("B").ToString()))
Next

End Class

When calling Foo.ShowDataView(), 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

Jul 21 '05 #4
You could also use:

Dim iterator As IEnumerator = dv.GetEnumerator
While iterator.MoveNext

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

Console.WriteLine(String.Concat(drv.Item("A").ToSt ring(), " - ",
drv.Item("B").ToString()))

End While
"Jim Hughes" <NO*********@Hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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.WriteLine(String.Concat(eachrow.Item("A"). ToString(), " - ",
eachrow.Item("B").ToString()))

Next

"Raymond Lewallen" <Ra******************@nospam.faa.gov> wrote in message
news:Om**************@TK2MSFTNGP14.phx.gbl...
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.GetMyDataview()
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.Add(drow)

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

For Each eachRow As DataRow In dv.Table.Rows
Console.WriteLine(String.ConCat(eachRow.Item("A"). ToString(),
" - ", eachRow.Item("B").ToString()))
Next

End Class

When calling Foo.ShowDataView(), 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


Jul 21 '05 #5
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" <No************@comcast.netNoSpamM> wrote
in message news:AA**********************************@microsof t.com...
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:
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.GetMyDataview()
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.Add(drow)

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

For Each eachRow As DataRow In dv.Table.Rows
Console.WriteLine(String.ConCat(eachRow.Item("A"). ToString(), " - ", eachRow.Item("B").ToString()))
Next

End Class

When calling Foo.ShowDataView(), 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

Jul 21 '05 #6
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
http://rlewallen.blogspot.com

"Jim Hughes" <NO*********@Hotmail.com> wrote in message
news:Or*************@TK2MSFTNGP14.phx.gbl...
You could also use:

Dim iterator As IEnumerator = dv.GetEnumerator
While iterator.MoveNext

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

Console.WriteLine(String.Concat(drv.Item("A").ToSt ring(), " - ",
drv.Item("B").ToString()))

End While
"Jim Hughes" <NO*********@Hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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.WriteLine(String.Concat(eachrow.Item("A"). ToString(), " - ",
eachrow.Item("B").ToString()))

Next

"Raymond Lewallen" <Ra******************@nospam.faa.gov> wrote in message news:Om**************@TK2MSFTNGP14.phx.gbl...
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.GetMyDataview()
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.Add(drow)

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

For Each eachRow As DataRow In dv.Table.Rows
Console.WriteLine(String.ConCat(eachRow.Item("A"). ToString(), " - ", eachRow.Item("B").ToString()))
Next

End Class

When calling Foo.ShowDataView(), 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



Jul 21 '05 #7
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
http://rlewallen.blogspot.com

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Raymond,

Does this show it you?

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

Cor

"Raymond Lewallen" <Ra******************@nospam.faa.gov>
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.GetMyDataview()
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.Add(drow)

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

For Each eachRow As DataRow In dv.Table.Rows
Console.WriteLine(String.ConCat(eachRow.Item("A"). ToString(),
" - ", eachRow.Item("B").ToString()))
Next

End Class

When calling Foo.ShowDataView(), 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


Jul 21 '05 #8
Hi Raymond,

"Raymond Lewallen" <Ra******************@nospam.faa.gov> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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.
foreach (DataRowView rowView in view)
Console.WriteLine(rowView["Column"]);

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?
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
www.rthand.com

--

Raymond Lewallen

"Cowboy (Gregory A. Beamer) - MVP" <No************@comcast.netNoSpamM>
wrote
in message news:AA**********************************@microsof t.com...
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:
> 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.GetMyDataview()
> 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.Add(drow)
>
> ' HERE IS THE PROBLEM. SORT DOES NOT SORT.
> dv.Sort = "A"
>
> For Each eachRow As DataRow In dv.Table.Rows
> Console.WriteLine(String.ConCat(eachRow.Item("A"). ToString(), > " - ", eachRow.Item("B").ToString()))
> Next
>
> End Class
>
> When calling Foo.ShowDataView(), 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
>
>
>


Jul 21 '05 #9
> 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.
Why don't you just use DataView?


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

Thank you for posting a solution,

--

Raymond Lewallen
Jul 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: jwedel_stolo | last post by:
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...
5
by: David Wender | last post by:
I want to create a dataview with a sort on multiple columns. However, when I use FindRows, I only want to search some of the columns, not all. Is...
9
by: Raymond Lewallen | last post by:
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 ...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.