473,396 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Sorting a dataview

I have a defaultview of a data table
in a typed dataset. When I first populate
a tree view with the contents of the dataset
the records are in the correct sort order.

After adding a new record to the dataset, and
then refreshing the draw tree routine, the new
record is not in the correct sort order.

Is there anything that I should do to get the
sort order of the updated table/dataview to
refresh to include the new record?

Below is a small segment of code that sets the
defaultview sort property of the datatable in the
typed data set.

When I step through each of the rows in the
myComments() array the records are not in the
sort order specified.

Dim myCommentDR As DesignDataSet.CommentRow
myDesignDS.Comment.DefaultView.Sort = "cDate DESC"
Dim myComments() As DesignDataSet.CommentRow
myComments =
myProjectDR.GetChildRows("FK_Comment_Project")

For Each myCommentDR In myComments
........

Does anybody have any thgouhts on how I can
correct this logical error.

Thanks,

Jason.
Nov 20 '05 #1
11 2723
In the sort property, just use the column name in quotes

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Jason L James" <ja***@no-spam.dive-master.org> wrote in message
news:40**************@news.newnet.co.uk...
I have a defaultview of a data table
in a typed dataset. When I first populate
a tree view with the contents of the dataset
the records are in the correct sort order.

After adding a new record to the dataset, and
then refreshing the draw tree routine, the new
record is not in the correct sort order.

Is there anything that I should do to get the
sort order of the updated table/dataview to
refresh to include the new record?

Below is a small segment of code that sets the
defaultview sort property of the datatable in the
typed data set.

When I step through each of the rows in the
myComments() array the records are not in the
sort order specified.

Dim myCommentDR As DesignDataSet.CommentRow
myDesignDS.Comment.DefaultView.Sort = "cDate DESC"
Dim myComments() As DesignDataSet.CommentRow
myComments =
myProjectDR.GetChildRows("FK_Comment_Project")

For Each myCommentDR In myComments
........

Does anybody have any thgouhts on how I can
correct this logical error.

Thanks,

Jason.

Nov 20 '05 #2
I thought that was what I had done, except that I want
them sorted in descending order. Yet it doesn't appear
to work with a newly added redcord.

On Fri, 16 Jul 2004 20:39:20 +0100, "One Handed Man \( OHM - Terry
Burns \)" <news.microsoft.com> wrote:
In the sort property, just use the column name in quotes

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Jason L James" <ja***@no-spam.dive-master.org> wrote in message
news:40**************@news.newnet.co.uk...
I have a defaultview of a data table
in a typed dataset. When I first populate
a tree view with the contents of the dataset
the records are in the correct sort order.

After adding a new record to the dataset, and
then refreshing the draw tree routine, the new
record is not in the correct sort order.

Is there anything that I should do to get the
sort order of the updated table/dataview to
refresh to include the new record?

Below is a small segment of code that sets the
defaultview sort property of the datatable in the
typed data set.

When I step through each of the rows in the
myComments() array the records are not in the
sort order specified.

Dim myCommentDR As DesignDataSet.CommentRow
myDesignDS.Comment.DefaultView.Sort = "cDate DESC"
Dim myComments() As DesignDataSet.CommentRow
myComments =
myProjectDR.GetChildRows("FK_Comment_Project")

For Each myCommentDR In myComments
........

Does anybody have any thgouhts on how I can
correct this logical error.

Thanks,

Jason.



Nov 20 '05 #3
Hi Jason

the full text is

Item ASC or Item DESC where ASC is default

I hopet this helps?

Cor
Nov 20 '05 #4
This is the text that I used:

myDesignDS.Comment.DefaultView.Sort = "cDate DESC"

and yet it still does appear to sort the records in the
dataview once a new record has been added.

Do you know of any reason why this might be the case?

Thanks,

Jason.

On Sat, 17 Jul 2004 08:51:49 +0200, "Cor Ligthert"
<no**********@planet.nl> wrote:
Hi Jason

the full text is

Item ASC or Item DESC where ASC is default

I hopet this helps?

Cor


Nov 20 '05 #5
Hi Jason,

I never use the defaultview however always the dataview, and before I try it
can you try it yourself with that, something as

Dim dv as new dataview(myDesignDs.tables("Comment")
or your strongly typed variant which I also not use
dv.sort = "cDate DESC"
mydatagrid1.datasource = dv

And when it still is not working add the row using
dv.AddRow

And when than still not
datagrid1.refresh

And when than still not show than some code.

:-)

Cor
Nov 20 '05 #6
Thanks Cor. I'll give it a go.

Jason.

On Sat, 17 Jul 2004 10:06:32 +0200, "Cor Ligthert"
<no**********@planet.nl> wrote:
Hi Jason,

I never use the defaultview however always the dataview, and before I try it
can you try it yourself with that, something as

Dim dv as new dataview(myDesignDs.tables("Comment")
or your strongly typed variant which I also not use
dv.sort = "cDate DESC"
mydatagrid1.datasource = dv

And when it still is not working add the row using
dv.AddRow

And when than still not
datagrid1.refresh

And when than still not show than some code.

:-)

Cor


Nov 20 '05 #7
Cor,

my issue is actually not with the datagrid, but with
a chunk of code to represent the database on
a treeview control.

The datagrid stuff works fine. But since my treeview
must process child rows based on a relationship,
and getchildrows(rel_name) returns an array
of row objects, I think I need them sorted before
I execute the getchildrows command since once I
have run the command I have an array of
child rows and not a DV to sort. I only seem
to be able to sort a DV and yet the getchildrows
only works on a table in a dataset!

THis one's getting a bit tricky to solve.

Do you have any other ideas or pointers
that might be useful.

The code I am using to process the dataset and
load it into the treeview is below.

myDesignDS is my typed dataset object. DesignDataSet
is by typed class. It has three tables called Project,
Comment and Attachment. tvProjects is my TreeView.

Dim myProjectDR As DesignDataSet.ProjectRow
For Each myProjectDR In myDesignDS.Project.Rows
Dim ProjectNode As New TreeNode
ProjectNode.Text = myProjectDR.pProjectName

Dim myCommentDR As DesignDataSet.CommentRow
myDesignDS.Comment.DefaultView.Sort = "cDate DESC"
Dim myComments() As DesignDataSet.CommentRow
myComments =myProjectDR.GetChildRows("FK_Comment_Project")

For Each myCommentDR In myComments
Dim CommentNode As New TreeNode
CommentNode.Text =myCommentDR.dComment

Dim myAttach As DesignDataSet.AttachmentRow
Dim myAttachments() As DesignDataSet.AttachmentRow
myAttachments = myCommentDR.GetAttachmentRows
For Each myAttach In myAttachments
Dim myAttachNode As New TreeNode
myAttachNode.Text = myAttach.aName

CommentNode.Nodes.Add(myAttachNode)
Next
ProjectNode.Nodes.Add(CommentNode)
Next
tvProjects.Nodes.Add(ProjectNode)
Next

Once again, many thanks,

Jason.

On Sat, 17 Jul 2004 10:06:32 +0200, "Cor Ligthert"
<no**********@planet.nl> wrote:
Hi Jason,

I never use the defaultview however always the dataview, and before I try it
can you try it yourself with that, something as

Dim dv as new dataview(myDesignDs.tables("Comment")
or your strongly typed variant which I also not use
dv.sort = "cDate DESC"
mydatagrid1.datasource = dv

And when it still is not working add the row using
dv.AddRow

And when than still not
datagrid1.refresh

And when than still not show than some code.

:-)

Cor


Nov 20 '05 #8
Hi Jason,

I did send a little bit else because I had changed it this code yesterday to
somebody,

It sorts a dataset, that you should not use. It is the use of the
datarowview where I want to point you on, that part is not easy to find
in/on MSDN.

Because of your code of the threeview I saw, I assume that you can implement
the rest yourself.

(That dvr.Row can be as well dvr("mycolumn"))

\\\
Dim dv As New DataView(dt)
dv.Sort = "bla DESC"
Dim dtnew As DataTable = dt.Clone
For Each dvr As DataRowView In dv
dtnew.ImportRow(dvr.Row)
Next
dt.Clear()
dt = dtnew.Copy
///

I hope this helps?

Cor
Nov 20 '05 #9
Cor,

thanks for the help this morning. I ended up using a dataview
of the table, setting the sort order and then the row filter,
instead of getchildrows. Had to dump some of the
typed DS stuff to make it work, but all seems fine now.

Below is the code. I would appreciate any comments
on improving it if you have the time.

For Each myProjectDR In myDesignDS.Project.Rows
Dim ProjectNode As New TreeNode
ProjectNode.Text = myProjectDR.pProjectName
myDesignDS.Comment.DefaultView.Sort = "cDate DESC"
Dim myCommentDV As DataView =
myDesignDS.Comment.DefaultView
myCommentDV.RowFilter = "cpID = " & myProjectDR.pID
Dim myComments As DataRowView 'DesignDataSet.CommentRow
For Each myComments In myCommentDV 'myComments
Dim CommentNode As New TreeNode
CommentNode.Text =myComments(4)
myDesignDS.Attachment.DefaultView.Sort = "aName ASC"
Dim myAttachDV As DataView =
myDesignDS.Attachment.DefaultView
myAttachDV.RowFilter = "acID = " & myComments(0)
Dim myAttachment As DataRowView
For Each myAttachment In myAttachDV
Dim myAttachNode As New TreeNode
myAttachNode.Text = myAttachment(2)
CommentNode.Nodes.Add(myAttachNode)
Next
ProjectNode.Nodes.Add(CommentNode)
Next
tvProjects.Nodes.Add(ProjectNode)
Next

Thanks

Jason.

Nov 20 '05 #10
Hi Jason,

Congratulated, when it works, why changing, the only thing what probably can
when I see it well, is setting this out of the loop because it is dynamic.

myDesignDS.Attachment.DefaultView.Sort = "aName ASC"
Dim myAttachDV As DataView = myDesignDS.Attachment.DefaultView
myAttachDV.RowFilter = "acID = " & myComments(0)

However something I assume. so you can try and than it is even a peanut,
nobody will recognize.

Cor
,

thanks for the help this morning. I ended up using a dataview
of the table, setting the sort order and then the row filter,
instead of getchildrows. Had to dump some of the
typed DS stuff to make it work, but all seems fine now.

Below is the code. I would appreciate any comments
on improving it if you have the time.

For Each myProjectDR In myDesignDS.Project.Rows
Dim ProjectNode As New TreeNode
ProjectNode.Text = myProjectDR.pProjectName
myDesignDS.Comment.DefaultView.Sort = "cDate DESC"
Dim myCommentDV As DataView =
myDesignDS.Comment.DefaultView
myCommentDV.RowFilter = "cpID = " & myProjectDR.pID
Dim myComments As DataRowView 'DesignDataSet.CommentRow
For Each myComments In myCommentDV 'myComments
Dim CommentNode As New TreeNode
CommentNode.Text =myComments(4)
myDesignDS.Attachment.DefaultView.Sort = "aName ASC"
Dim myAttachDV As DataView =
myDesignDS.Attachment.DefaultView
myAttachDV.RowFilter = "acID = " & myComments(0)
Dim myAttachment As DataRowView
For Each myAttachment In myAttachDV
Dim myAttachNode As New TreeNode
myAttachNode.Text = myAttachment(2)
CommentNode.Nodes.Add(myAttachNode)
Next
ProjectNode.Nodes.Add(CommentNode)
Next
tvProjects.Nodes.Add(ProjectNode)
Next

Thanks

Jason.

Nov 20 '05 #11
Jason,
I would use a DataView for the outer loop, then use DataViewRow.GetChildView
to get the children for that row.

Something like:

For Each myProject As DataRowView In myDesignDS.Project.DefaultView
Dim ProjectNode As New
TreeNode(myProject("pProjectName").ToString())

' get the comments for the project
Dim viewComment As DataView =
myProject.CreateChildView("ProjectComments")
viewComment.Sort = "cDate DESC"

For Each myComments As DataRowView In viewComment
Dim CommentNode As New TreeNode(myComments(4).ToString())

' get the attachments for the comment
Dim viewAttachment As DataView =
myComments.CreateChildView("CommentAttachments")
viewAttachment.Sort = "aName ASC"

For Each myAttachment As DataRowView In viewAttachment
Dim myAttachNode As New
TreeNode(myAttachment(2).ToString())
CommentNode.Nodes.Add(myAttachNode)
Next
ProjectNode.Nodes.Add(CommentNode)
Next
tvProjects.Nodes.Add(ProjectNode)
Next

The advantage of the CreateChildView is you don't have to worry about
creating a well formed RowFilter for the children, especially if the
relationship involves text fields and/or multiple fields.

Hope this helps
Jay
"Jason L James" <ja***@no-spam.dive-master.org> wrote in message
news:40***************@news.newnet.co.uk...
Cor,

thanks for the help this morning. I ended up using a dataview
of the table, setting the sort order and then the row filter,
instead of getchildrows. Had to dump some of the
typed DS stuff to make it work, but all seems fine now.

Below is the code. I would appreciate any comments
on improving it if you have the time.

For Each myProjectDR In myDesignDS.Project.Rows
Dim ProjectNode As New TreeNode
ProjectNode.Text = myProjectDR.pProjectName
myDesignDS.Comment.DefaultView.Sort = "cDate DESC"
Dim myCommentDV As DataView =
myDesignDS.Comment.DefaultView
myCommentDV.RowFilter = "cpID = " & myProjectDR.pID
Dim myComments As DataRowView 'DesignDataSet.CommentRow
For Each myComments In myCommentDV 'myComments
Dim CommentNode As New TreeNode
CommentNode.Text =myComments(4)
myDesignDS.Attachment.DefaultView.Sort = "aName ASC"
Dim myAttachDV As DataView =
myDesignDS.Attachment.DefaultView
myAttachDV.RowFilter = "acID = " & myComments(0)
Dim myAttachment As DataRowView
For Each myAttachment In myAttachDV
Dim myAttachNode As New TreeNode
myAttachNode.Text = myAttachment(2)
CommentNode.Nodes.Add(myAttachNode)
Next
ProjectNode.Nodes.Add(CommentNode)
Next
tvProjects.Nodes.Add(ProjectNode)
Next

Thanks

Jason.

Nov 20 '05 #12

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

Similar topics

1
by: Dave S | last post by:
Hi, I'm using a datagrid to display contents of a dataset and I've set the datagrid to allow paging and sorting. Rather than re-retrieve from the DB, I store the original dataset in a Session...
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 in order to determine the sort order of the...
11
by: Nikki | last post by:
Is it possible to sort a dataset rather than a dataview? I have a web service that returns a dataset which I would like to sort before returning it (this is so the sorting is standardised and so...
12
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that...
2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
4
by: suzy | last post by:
hello. how can i sort data in a dataset? all the examples i have seen on msdn, etc are sorting a dataview. this works fine, but i want to return the results in xml and the dataview doesn't...
1
by: Jeremy | last post by:
I want my gird to sort only the items on the current page when I click on a column header. I wrote a little test app, but when I sort it pulls in items from other pages and places them on the current...
6
by: David P. Donahue | last post by:
I've been looking around for ways to sort the rows in a DataTable, and everything seems to point to just changing the Sort property on that DataTable's DefaultView property. That's all well and...
4
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have a vb.net 2.0 app that is loading a GridView with a DataSource that is returned from a function. The definitions in the function are: Dim ReportDS As DataSet = New DataSet Dim...
1
by: castron | last post by:
Hello All, I have a grid view that allows sorting, paging, editing, etc. Under On Load event, if I check: if(!IsPostBack){ DisplayData(); }, the Edit portion works fine. However, the Sorting...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.