Link to home
Start Free TrialLog in
Avatar of Massiel_VB
Massiel_VB

asked on

Sorting a DataView?

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?
Avatar of tnewc59
tnewc59

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"

Avatar of Massiel_VB

ASKER

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..
ASKER CERTIFIED SOLUTION
Avatar of Rusk
Rusk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, you are right: it works now,
Thank u very much