Solved

Sorting a DataView?

Posted on 2002-07-20
4
253 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
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…

756 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