Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
There are 2 grids in which i have to display data in sorted form
for 1st grid - data with high price
for 2nd grid - data with low value

i am getting the data in a string array (string[5][4])
i.e. data[0-5]{string []{"value","high price","low value","qty"}}


e.g.

string[][] newval = new string[][] { 
    new string[]{"12","113.12","121.90","12"},
    new string[]{"12","111.15","121.95","12"},
    new string[]{"12","115.16","121.92","12"},
    new string[]{"12","116.13","121.98","12"},
    new string[]{"12","114.11","121.95","12"}};


each time data is coming in the format above & with 5 rows i have to fill these grids as(first 2 values for grid 1 & next 2 values for grid 2)

grid 1

high price-- value

grid 2

low value -- qty

i have to create a string array of 10 from the coming data as string[10][4] thus to display 10 rows in each grid condition grid 1 to be sorted on high price(data type double) and grid2 to be sorted on low value (data type double).
Posted
Updated 2-Aug-12 0:18am
v2

Hi,

Is this what you're asking?

C#
var list1 = newval.Select(x => new String[] { x[1], x[0] });
var list2 = newval.Select(x => new String[] { x[2], x[3] });


Hope it helps.

Edit: I'm missing the sort: List<t>.Sort[^]
 
Share this answer
 
v2
Comments
honeyashu 2-Aug-12 6:43am    
Didn't get this.. what will exactly this will do??
will this sort double values accurately which we are getting as string??
_Zorro_ 2-Aug-12 8:14am    
It will split you matrix into 2 arrays:

list1 will contain the high prices and the values
list2 will contain the low prices and the quantities

Then, you'll just need to sort those two lists as _Amy said.
Hi,
Try this:
C#
int[,] array = new int[3, 3] { { 1, 4, 2 }, { 4, 5, 1 }, { 7, 3, 8 } };
int[,] sortedByFirstElement = array.OrderBy(x => x[0]);
int[,] sortedBySecondElement = array.OrderBy(x => x[1]);
int[,] sortedByThirdElement = array.OrderBy(x => x[2]);

Refer this[^] also.



--Amit
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900