Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > .NET Frameworks (точка нет фреймворки) > C# (си шарп)
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 16.12.2011, 22:20   #1
Ese
Новичок
Джуниор
 
Регистрация: 16.12.2011
Сообщений: 1
По умолчанию Открытие вложенного *.txt файла в DataGridView

Доброго времени суток!
Пытаюсь открыть вложенный txt файл (или csv) в datagridview.
Пытаюсь открыть через потоки, ошибок нет но текст не грузится.
Как сделать загрузку
tf.txt загружен через VC# установлено свойство вложенный ресурс (embedded).
VC# 2010 express

Читал эту страницу по теме:
http://www.rsdn.ru/article/dotnet/resources.xml

В комментариях попытки подключения(мусор).

Код:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
 
namespace DataGridViewExample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            // Open the contact_list file for reading. File is placed in the debug folder.
            richTextBox1.Text = Resource1.tf1;
 
           
            //Stream st = this.GetType().Assembly.GetManifestResourceStream("tf1",Encoding.GetEncoding(1251));
 
 
           // StreamReader sr = new StreamReader(Resource1.tf1);
           StreamReader sr = new StreamReader (this.GetType().Assembly.GetManifestResourceStream("tf1.txt"), Encoding.GetEncoding(1251));
            
 
 
          
            //StreamReader sr = new StreamReader("contact_list.txt");
            // Variable to store each row.
            string dataRow = "";
            // String array needed to determin number of columns to use. 
           
            string[] headerRow;
            
            int columns = 0;
            // Object array used to store each line of data from the text file.
            object[] row;
 
            // Read the first line of the text file. Then split the data using a comma character
            headerRow = sr.ReadLine().Split(',');
            
            
            // Store the length of headerRow string array, this will tell us how many columns we need.
            columns = headerRow.Length;
 
            // "For Loop" below is used to add column headers to the DataGridView control. The name of each column
            // header begins with "Header" followed by a number. 
 
 
            
 
            for (int cols = 0; cols < columns; cols++)
            {
                dgv.Columns.Add("Header " + cols, "Header " + cols);
            }
 
            // At this point, column headers have been added.
            // Now all that remains is to add the rows. Read the file line by line, using a while loop
            // and the ReadLine() method. When reading each line make sure it is not a blank line. If it is a blank line
            // skip the line and read the next line. 
 
            while ((dataRow = sr.ReadLine()) != null)
            {
                if (dataRow != "")
                {
                    row = dataRow.Split(','); // Split the dataRow string variable and store each data into an Object array.
                    dgv.Rows.Add(row); // Add the row.
                }
            }
 
        }
    }
}
Спасибо!
Вложения
Тип файла: rar DataGridViewExample.rar (44.6 Кб, 26 просмотров)
Ese вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
чтение и отображение из ".txt" файла в dataGridView Leva_89 C# (си шарп) 0 23.03.2011 23:23
открытие txt в Memo НиРа Помощь студентам 8 19.12.2010 14:39
Как скопировать текст с файла 1.txt и записать в 2.txt Kasper1 Общие вопросы по Java, Java SE, Kotlin 1 14.12.2010 05:56
Повторное открытие файла txt для редактирования в delphi Shaggrath Помощь студентам 8 20.07.2009 13:36
txt в DataGridView kommunist Общие вопросы .NET 1 25.05.2008 20:43