By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,131 Members | 1,728 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,131 IT Pros & Developers. It's quick & easy.

Sorting multiple dimensions of an array

P: n/a
Hi All,

Is there a way to sort multiple dimensions of an array in VB.NET? Let's say
I have the following in a multi-dimension array:

3081 100 2
3081 100 1
3081 20 1
3081 1 2
3021 100 2
3021 100 1
3021 20 1
3021 1 2

I need to sort the first dimension, then the 2nd, then the 3rd, to get:

3021 1 2
3021 20 1
3021 100 1
3021 100 2
3081 1 2
3081 20 1
3081 100 1
3081 100 2

Initially, I put the values together in one string, like 3021-1-2 in a
single dimension array, then sorted that, but, because the value is a
string, the sort result is not what I'm looking for. Instead, I get:

3021-1-2
3021-100-1
3021-100-2
3021-20-1
etc.

I know I can create a dataset, table, columns, etc. and use a grid that
supports multi-column sorting, but I don't need the grid. I just need to
sort the array.

Eventually, this data is combined with other data and streamed out to a
file. I can live with the string sort as above, but I'd prefer to sort the
multi-dimension array so that the result is a correct numeric sort.

any ideas?

TIA

Lee
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
lgbjr,

I know I can create a dataset, table, columns, etc. and use a grid that
supports multi-column sorting, but I don't need the grid. I just need to
sort the array.

I miss something above can you tell me what?

http://www.windowsformsdatagridhelp....7-d6ad9bebf57f

You can of course make as well a routine using the icomparer, however for me
it would be to much work because this is so easy to do.

I hope this helps,

Cor
Nov 21 '05 #2

P: n/a

"lgbjr" <lg***@nospam.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Hi All,

Is there a way to sort multiple dimensions of an array in VB.NET? Let's say I have the following in a multi-dimension array:

3081 100 2
3081 100 1
3081 20 1
3081 1 2
3021 100 2
3021 100 1
3021 20 1
3021 1 2

I need to sort the first dimension, then the 2nd, then the 3rd, to get:

3021 1 2
3021 20 1
3021 100 1
3021 100 2
3081 1 2
3081 20 1
3081 100 1
3081 100 2


Seems 2 me that since the dimensions are apparently not related, it would be
easier to just use 3 separate arrays, then sort each separately.
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.