Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am extracting data from a text file & storing it in an array using the Following Code-

C#
public class data
        {
            public string date, time, mag, depth;
            public double lat, lon;
        }
        private void view_file_Load(object sender, EventArgs e)
        {

            string str;
            List<data> gd = new List<data>();
            try
            {
                using (StreamReader sr = new StreamReader("C:\\Windows\\Temp\\op.txt"))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        string[] arr = line.Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries);
                        while (sr.Peek() > 0)
                        {

                            string[] s = new string[] { " " };
                            char[] c = new char[] { ' ' };
                            str = sr.ReadLine();
                            arr = str.Split(c);

                            data d = new data();
                            d.date = arr[0];
                            d.time = arr[1];
                            d.lat = Convert.ToDouble(arr[3]);
                            d.lon = Convert.ToDouble(arr[4]);
                            d.depth = arr[7];
                            d.mag = arr[8];


                        }

now i want to display those array elements into datagridview, how do i achieve this?
Posted
Comments
Kenneth Haugland 28-Jul-13 12:11pm    
DataGridView.ItemsSource = gd?
Member 8657306 28-Jul-13 12:20pm    
i dont get the .itemsource option..
Boipelo 28-Jul-13 12:39pm    
Add your data into a DataTable, exactly as you did from "data d = new data()", but this time create a DataTable. Bind that to the Grid --GridView.DataSource and GridView.Databind().
ridoy 28-Jul-13 12:47pm    
same question in 2 formats?! no 1.access database and here no 2. in gridview!
ridoy 28-Jul-13 12:59pm    
i agree with Boipelo,alternatively you can create a List with the elements of d.date,d.time etc and set dataGridView1.DataSource = yourList;

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