Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace asas
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         OpenFileDialog fisier = new OpenFileDialog( );
  17.         string line = "";
  18.         private object valori;
  19.  
  20.         public Form1( )
  21.         {
  22.             InitializeComponent( );
  23.         }
  24.  
  25.         private void button1_Click( object sender, EventArgs e )
  26.         {
  27.             DataTable tabel = new DataTable( );
  28.             DataRow rand = tabel.NewRow( );
  29.             tabel.Rows.Add( rand );
  30.  
  31.             dataGridView1.DataSource = tabel;
  32.  
  33.             if (fisier.ShowDialog( ) == DialogResult.OK)
  34.             {
  35.                 StreamReader file = new StreamReader( fisier.FileName );
  36.  
  37.                 string[] coloane = file.ReadLine( ).Split( ' ' );
  38.                 //DataTable tabel = new DataTable( );
  39.                 foreach (string c in coloane)
  40.                 {
  41.                     tabel.Columns.Add( c );
  42.                 }
  43.  
  44.                 string linie;
  45.  
  46.                 while (( linie = file.ReadLine( ) ) != null)
  47.                 {
  48.                     rand = tabel.NewRow( );
  49.                     string[] valori = linie.Split( ' ' );
  50.  
  51.                     for (int i = 0; i < valori.Length; i++)
  52.                     {
  53.                         rand[i] = valori[i];
  54.                     }
  55.                     tabel.Rows.Add( rand );
  56.                 }
  57.                 dataGridView1.DataSource = tabel;
  58.             }
  59.            
  60.         }
  61.  
  62.         private void Form1_Load( object sender, EventArgs e )
  63.         {
  64.             fisier.Filter = "Text Files (.txt) | *.txt";
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement