I'm trying to make a leader board that sorts each participant by the score they get. Each user will say whether they have one or lost then the code gives the win or loss a number. This then gets added to a listbox and is saved in a .txt file. My issue is i want to sort the leader board by what they've scored. Below is all the code from the file just so you know what I'm working with
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class BadForm : Form
{
public BadForm()
{
InitializeComponent();
}
private void BackBut_Click(object sender, EventArgs e)
{
this.Hide();
TeaEveSel f4 = new TeaEveSel();
f4.Show();
// This shows the team event selection page when the button is pressed
}
private void HomeBut_Click(object sender, EventArgs e)
{
this.Hide();
StartForm f4 = new StartForm();
f4.Show();
// This shows the start up page when the button is pressed
}
private void TeaSave_Click(object sender, EventArgs e)
{
if (ResultsBox.Text == "Win")
{
ResultsBox.Text = 5.ToString(); // Whenever win is selected it changes to the number 5 so that calculations can be done
}
else if (ResultsBox.Text == "Lose")
{
ResultsBox.Text = 1.ToString(); // Whenever lose is selected it changes to the number 1 so that calculations can be done
}
else
{
}
listBox1.Items.Add(string.Format("{0} | {1} | {2} | {3}", IndNamBox.Text, TeaNamBox.Text, EveNamBox.Text, ResultsBox.Text));
listBox1.Items.Add("");
//This adds the text in the combo boxes and text boxes to the list box
}
private void TeaTable_Click(object sender, EventArgs e)
{
const string fpath = "G:\\IT\\unit 4\\assignment 2\\WindowsFormsApp1\\Badminton.txt";
var SaveFile = new System.IO.StreamWriter(fpath);
foreach (var item in listBox1.Items)
{
SaveFile.WriteLine(item.ToString());
}
SaveFile.ToString();
SaveFile.Close();
//When this button is pressed it updates the txt file with the text in the list box
BigServer frm2 = new BigServer();
frm2.Show();
frm2.Hide();
//This opens and closes the BigServer form so that the listbox on the BigServer loads the txt file
}
private void BadForm_Load(object sender, EventArgs e)
{
var lines = File.ReadAllLines("G:\\IT\\unit 4\\assignment 2\\WindowsFormsApp1\\Badminton.txt");
listBox1.Items.AddRange(lines);
//This fills the listbox with the txt file so that all the information is in the file and nothing gets overwritten.
}
}
}
I know there's a lot but The context is very important. Any help would be great. If i could sort the listbox before saving to the .txt file then that would also work.