Dataview not in order after Sort

P

Pewak

Hi,

I am adding a row to the datatable, and then I want to sort it, so I
put this into a dataview, and use the following code to sort it, but
it stays in the same order after I've done it.

datatable.rows.add(newrow)

dim dv as dataview

dv = datatable.DefaultView
dv.Sort = ("process_desc")

where process_desc is the name of the column to order, but it stays in
the same order. Any ideas why this is???
 
M

Miha Markic [MVP C#]

Hi Pewak,

DataView does not sort DataTable, it only represents the data in sorted
order.
 
P

Pete Walker

hi Miha ,

I have looked at the dataview after the sort on the column and it
appears in the same order. I intend to append this dataview into a new
dataset after the sort. Have you any suggestions how to do this ?
 
C

Cor

Hi Pete,

I see no function for it, but what you can do is clone a dataset and than
while itterating thru your dataview add new rows for that new dataset and
than copy the items using the dataview to that new dataset also itterating
thru that.

It is not a real big job to do, I think about 10 rows of code in vb and 20
in C# (including {})

Cor
 
M

Miha Markic [MVP C#]

Hi Pete,

One solution was provided by Cor.
However, why would you want to copy sorted rows?
 
P

Pete Walker

Sorry, I didn't explain myself clearly, I have 3 seperate datasets that
have to be bound into one datagrid, because as far as I know you can't
bind multiple datasets to one datagrid, so I thought the best way was to
merge these 3 datasets into one like follows and then bind the merged
dataset into the datagrid. (hope this makes sense !!!)

1st Dataset
Overall Figure xxx yyy zzz

2nd Dataset (the bit I want in order)
A xxx yyy zzz
B xxx yyy zzz
C xxx yyy zzz
D xxx yyy zzz

3rd Dataset
Total Figure

This is where I wanted the 2nd dataset sorted
 
N

noeldp

good news - you can get at the sorted dataview if you use the correct
syntax (credit goes to somebody else, i can't find the link right
now)

this syntax works, it returns the rows in sorted order:

dataview.sort "some column name"
for i = 0 to dataview.count - 1
dataview(i).item()

this syntax fails to return it in sorted order:

dataview.sort "some column name"
for i = 0 to dataview.table.rows.count - 1
dataview.table.row(i).item()

if you think this is silly, why not provide a dataset.sort method in
the first place, right?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top