-1

I'm looking to display the top three customers and their total amounts from a textfile in the listbox/listview when the form is loaded, I was wondering if this is possible using arrays? There are multiple figures in the textfile including other inital investment amounts, interest amounts. So i need it to find just the total amount and the top 3 customers names.

So far I've tried this and it doesn't work,Would listbox or listview work better and should there be another way i should be trying it? so i was wondering if you could help me with this? Thanks :)

    private void Form5_Load(object sender, EventArgs e)
    {
     foreach (var line in File.ReadLines("transactions.txt"))

   {

listView1.View = View.Details;
listView1.HeaderStyle = ColumnHeaderStyle.None;
listView1.Columns.Add(new ColumnHeader { Width = listView1.ClientSize.Width - SystemInformation.VerticalScrollBarWidth });

 int[] array = new int[] {};
 int[] largest = array
                .OrderByDescending(item => item)
                .Take(array.Length).ToArray();}

   //Here is the code for the transactions.txt file and what it contains.
             public void CreateFile()
{
     StreamWriter outputFile;
        outputFile = File.AppendText("transactions.txt");
        outputFile.WriteLine("Transaction Number :" + " " + TransactionIDLabel.Text);
        outputFile.WriteLine("Investor :" +" " + InvestorNameLabel.Text);
        outputFile.WriteLine("Initial Amount" + " " +AmountLabel.Text);
        outputFile.WriteLine("Date Invested" +" " +DateLabel.Text);
        outputFile.WriteLine("Period Chosen" + " "+DaysInvestedLabel.Text);
        outputFile.WriteLine("Rate Chosen" + " " + RateLabel.Text);
        outputFile.WriteLine("Total Interest" + " " +InterestAmountLabel.Text);
        outputFile.WriteLine("");
        outputFile.Close();
  }
user2884461
  • 109
  • 1
  • 2
  • 9

1 Answers1

0

Your code has incomplete(maybe incorrect). If you want to find first top 3 you should use

array.OrderByDescending(item => item).Take(3)

and I'm not find what is

listView1.View = View.Details; listView1.HeaderStyle =
ColumnHeaderStyle.None; listView1.Columns.Add(new ColumnHeader { Width
= listView1.ClientSize.Width - SystemInformation.VerticalScrollBarWidth });

foreach line in text you add column. ?!?

AlirezaJ
  • 111
  • 6