Solved

Sorting a DataView?

Posted on 2002-07-20
4
248 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Yes, you are right: it works now,
Thank u very much
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now