sort dataset by the length of content

M

Markus Heid

Hi,
I've got following issue: I'm creating a dataset during runtime. The Dataset
is unsorted. It may look this way unsorted:
pk_id value1 value2 string3
1 1 10 10, 20
2 1 11 14
3 2 100 1
4 2 101 20, 10
5 2 102 11
6 3 70 1, 10, 20
7 3 1 9

sorted it should look that way:

3 2 100 1
7 3 1 9
5 2 102 11
2 1 11 14
1 1 10 10, 20
4 2 101 20, 10
6 3 70 1, 10, 20

As you see I want to sort the dataset by the length of the content of the
field "string3". My first attempt
was to do it with a dataview:

DataView myView = new DataView( myDataTable );
myView.Sort = "len(string3)";

But that throws an exception that the column "len(string3)" is unknown.
Does anyone here knows how to do such a thing

I'm thankfull for every hint

Markus
 
M

Miha Markic [MVP C#]

Hi Markus,

Try this:
Add another (calculated) column and set its expression to "len(string3)";
Sort on this column.
 

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