Solved

Sorting a DataView?

Posted on 2002-07-20
4
251 Views
Last Modified: 2012-05-04
I'm tryng to add some menu items at runtime using values from a datatable. I will like the menu items to be sorted.

This is the code I'm using:

Dim myDataView As DataView
myDataView = myDataTable.DefaultView
myDataView.Sort = "MenuCaption ASC"

For intLoop = 0 To myDataView.Table.Rows.Count - 1
  strMenuCaption = myDataView.Table.Rows(intLoop).Item(1).ToString
  miMaintanence.MenuItems.Add(New MenuItem(strMenuCaption, New EventHandler(AddressOf Me.OpenMaintanenceForm_Clicked)))
Next

I get no errors and the menu items displays and work ok .. but they are not sorted!!!??

What's wrong with this code? Can u help me out?
0
Comment
Question by:Massiel_VB
  • 2
4 Comments
 
LVL 1

Expert Comment

by:tnewc59
ID: 7167360
I would try 2 things:

The query that is returning the data for myDataTable could be modified to have an order by "MenuCaption ASC"


If you wish to sort the dataview on the "MenuCaption" field, I think you need:
myDataView.Sort = "MenuCaption"

0
 

Author Comment

by:Massiel_VB
ID: 7167701
Thanks for your comments:

I know I can modifiy the qry (right now is not a qry but I'm doing a direct table access) and that will be my last resource.

What puzzle me is that the listview does not sort at all.
I tried:

myDataView.Sort="MenuCaption ASC"
and
myDataView.Sort = "MenuCaption" as u proposed.. but it doesn't worked..
0
 
LVL 2

Accepted Solution

by:
Rusk earned 25 total points
ID: 7170806
you are looping in the table I would try looping in the view
by mydataview(i)
instead of mydataview.table.rows(i)


For intLoop = 0 To myDataView.Table.Rows.Count - 1
 strMenuCaption = myDataView.Table.Rows(intLoop).Item(1).ToString
 miMaintanence.MenuItems.Add(New MenuItem(strMenuCaption, New EventHandler(AddressOf Me.OpenMaintanenceForm_Clicked)))
Next
0
 

Author Comment

by:Massiel_VB
ID: 7178729
Yes, you are right: it works now,
Thank u very much
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question