Click here to Skip to main content
14,970,653 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is so far what i have tried my hands on. but its not what i want; what i actually want this code to be capable of is to: rank each student in each subject such that; the highest mark/score in each subject will have the first (1st) position and next highest will have second (2nd) position in each subject and wherever within the textbox we have similar mark/score such two mark/score will have similar position in that subject and the ranking will continue in order of increment


What I have tried:

ok to be more lucid. what i actually mean is this i have a datagrid with defferent columns such as Id column, firstname, and columns of deferent subjects below is the sample:
![72801-capture.png][1]
when each row from the capture datagrid is selected then all the scores for each subject column is shown in the textbox1. like this:
![72736-captuere.png][2]

and when the button1 event is clicked with code below:

foreach(int mark in txtresult.ToString())

{
if (mark < 40)
{
string[] parts = textbox1.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
int[] numbers = parts.Select(p => int.Parse(p)).ToArray();
int maximum = numbers.Max();
int position = Array.IndexOf(numbers, maximum);
parts[position] = "1".ToString();
textbox1.Text = string.Join(" ", parts);
}
else if(mark >=40 && <50)
{
m="2th" position etc... within the above block of code
}


sample after button click event the fact is that the button click event is actually working on the integers in the textbox1 the code that brings the
this scores to the textbox is here: this code shows the scores in the textbox1 and the COMPUTE BUTTON above the SAVE GRADE button does the above code(by doing the arithmetic's)

string str;

DataGrid dg = sender as DataGrid;

DataRowView dr = dg.SelectedItem as DataRowView;
if (dr != null)
{
if (dgvGrade.SelectedItems.Count > 0)
{
foreach (var obj in dgvGrade.SelectedItems)
{
str += dr["ENGLISH"] + " " + dr["MATH"] + " " + dr["SCIENCE"] + " " + dr["LANGUAGE"] + " " + "";
}
}
else
{
//DO NOTHING
}
textbox1.Text = str;



![72785-capture.png][3]
this is so far what i have tried my hands on. but its not what i want; what i actually want this code to be capable of is to: rank each student in each subject such that; the highest mark/score in each subject will have the first (1st) position and next highest will have second (2nd) position in each subject and wherever within the textbox we have similar mark/score such two mark/score will have similar position in that subject and the ranking will continue in order of increment

eg.
![72756-capturle.png][4]

this is what i actually want my button click event to process but i cant do it so i posted this question for help please to the entire programmers i need Help
(am using c#, in WPF VS2019) Thanks in Advance
Posted
Updated 2-Mar-21 7:12am

1 solution

That code doesn't do any of what your teacher wants: he expects you to sort the values as described.

Start by looking at the OrderBy method: Enumerable.OrderBy Method (System.Linq) | Microsoft Docs[^]
   

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