Hi guys I need help with my C# winform app

below/attached the code

Thanks.

--------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace ListOfRunners
{
    public partial class Form1 : Form
    {
        //protected Runner runner;
        //protected List<Runner> listRunner;

        public Form1()
        {
            InitializeComponent();
            //runner = new Runner();
            //listRunner = new List<Runner>();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

           //Runner runner = new Runner();
            List<Runner> listRunner = new List<Runner>();

            StreamReader myReader = new StreamReader("TextFile1.txt");
            string line = "";

            do
            {
                line = myReader.ReadLine();

                if (line != null)
                {
                    listRunner.Add(GetRunnerDetails(line));
                }

            } while (line != null);

            myReader.Close();

            var query = from r in listRunner
                        //orderby r.Time
                        //select r;
                        select new { r.Name, r.Time, r.Age };

            dataGridView1.DataSource = query;

            foreach (var item in query)
            {
                MessageBox.Show("Name:" + item.Name);
            }
           



        }

        //Process each line of data to get the Participant object
        private Runner GetRunnerDetails(string line)
        {
            Runner runner = new Runner();
            line = line.Trim();

            //to get the name
            int delimiterIndex = line.IndexOf(" ");
            runner.Name = line.Substring(0, delimiterIndex);
            line = line.Replace(runner.Name, "");
            line = line.Trim();

            //to get age
            delimiterIndex = line.IndexOf(" ");
            runner.Time = int.Parse(line.Substring(0, delimiterIndex));
            line = line.Replace(runner.Time.ToString(), "");
            line = line.Trim();

            //to get the time
            runner.Age = int.Parse(line);

            return runner;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ListOfRunners
{
    class Runner
    {
        public string Name { get; set; }
        public int Time { get; set; }
        public int Age { get; set; }
        public int Ranking { get; set; }

        public void Print()
        {
            Console.WriteLine("{0} {1} {2}", Name, Time, Age);
        }
    }
}

Jay 12 33
Hem 34 28
Umesh 22 37
Tom 21 30
Cliff 13 33
Vini 17 28
Matt 10 28
Ben 9 29
Brandon 15 14

Edited 6 Years Ago by __avd: Added [code] tags.

Correction:

......
           var query = from r in listRunner
                        //orderby r.Time
                        //select r;
                        select new {  r.Name, r.Time, r.Age };

            dataGridView1.DataSource = query.ToList();
   }

Correction:

......
           var query = from r in listRunner
                        //orderby r.Time
                        //select r;
                        select new {  r.Name, r.Time, r.Age };

            dataGridView1.DataSource = query.ToList();
   }

Thanks a lot, it's working now.


But can you explain me why in this part of the code. There is no need to do that ?

----------------------------------------------------
private void Form1_Load(object sender, EventArgs e)
{
ObjectQuery<PersonName> personNameQuery = personNameContext.PersonName;
dgvPersonName.DataSource = personNameQuery;
dgvPersonName.Columns["ID"].Visible = false;
}
----------------------------------------------------
link to the code above -->http://www.codeproject.com/KB/database/IntroEntityFramework3.aspx

This article has been dead for over six months. Start a new discussion instead.