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.Coun t - 1
strMenuCaption = myDataView.Table.Rows(intL oop).Item( 1).ToStrin g
miMaintanence.MenuItems.Ad d(New MenuItem(strMenuCaption, New EventHandler(AddressOf Me.OpenMaintanenceForm_Cli cked)))
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?
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.Coun
strMenuCaption = myDataView.Table.Rows(intL
miMaintanence.MenuItems.Ad
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?
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="MenuCapti on ASC"
and
myDataView.Sort = "MenuCaption" as u proposed.. but it doesn't worked..
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="MenuCapti
and
myDataView.Sort = "MenuCaption" as u proposed.. but it doesn't worked..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, you are right: it works now,
Thank u very much
Thank u very much
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"