Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace asas
- {
- public partial class Form1 : Form
- {
- OpenFileDialog fisier = new OpenFileDialog( );
- string line = "";
- private object valori;
- public Form1( )
- {
- InitializeComponent( );
- }
- private void button1_Click( object sender, EventArgs e )
- {
- DataTable tabel = new DataTable( );
- DataRow rand = tabel.NewRow( );
- tabel.Rows.Add( rand );
- dataGridView1.DataSource = tabel;
- if (fisier.ShowDialog( ) == DialogResult.OK)
- {
- StreamReader file = new StreamReader( fisier.FileName );
- string[] coloane = file.ReadLine( ).Split( ' ' );
- //DataTable tabel = new DataTable( );
- foreach (string c in coloane)
- {
- tabel.Columns.Add( c );
- }
- string linie;
- while (( linie = file.ReadLine( ) ) != null)
- {
- rand = tabel.NewRow( );
- string[] valori = linie.Split( ' ' );
- for (int i = 0; i < valori.Length; i++)
- {
- rand[i] = valori[i];
- }
- tabel.Rows.Add( rand );
- }
- dataGridView1.DataSource = tabel;
- }
- }
- private void Form1_Load( object sender, EventArgs e )
- {
- fisier.Filter = "Text Files (.txt) | *.txt";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement