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
Solved

Sorting a DataView?

Posted on 2002-07-20
4
252 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 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