言語はC#です
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ComicSearch
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button_File_Click(object sender, EventArgs e)
{//csvファイルの呼び出し
OpenFileDialog ofd = new OpenFileDialog();
ofd.FileName = "";
ofd.InitialDirectory = @"C:\";
ofd.Filter = "csvファイル(*.csv)|*.csv|すべてのファイル(*.*)|*.*";
ofd.FilterIndex = 1;
ofd.Title = "csvファイルを選択してください";
ofd.RestoreDirectory = true;
if (ofd.ShowDialog() != DialogResult.OK) return;
this.textBox_File.Text = ofd.FileName;
}
private void button_Read_Click(object sender, EventArgs e)
{
clsRead clRead = new clsRead() ;
if (radioButton_ComicDatta.Checked) clRead.comicDataRead(textBox_File.Text); //ここで呼び出してます
else if (radioButton_Search.Checked) clRead.searchRead(textBox_File.Text);
else return;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.VisualBasic.FileIO;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ComicSearch
{
public class clsRead
{
static int COMIC_AROW = 2048; //発売コミック行数
static int SEARCHAROW = 32; //検索コミック行数
public void comicDataRead(string stFileName)
{
//ファイル読み込み
TextFieldParser clParser = new TextFieldParser(stFileName, Encoding.GetEncoding("Shift_JIS"));
clParser.TextFieldType = FieldType.Delimited;
clParser.SetDelimiters(","); //区切り文字はコンマ
while (!clParser.EndOfData)
{
string[] row = clParser.ReadFields(); // 1行読み込み
// 読み込んだデータ(1行をDataGridViewに表示する)
dataGridView_ComicData.Rows.Add(row); //←ここでエラーになります
return;
}
}
public void searchRead(string stFileName)
{
StreamReader sr = new StreamReader(stFileName, Encoding.GetEncoding("Shift_JIS"));
string text = sr.ReadToEnd();
sr.Close();
Console.Write(text);
return;
}
}
}
csvファイルを読み込んdataGridViewに書き込みたいんですが上記の部分でエラーが出ます
えらーは
名前 'dataGridView_ComicData' は現在のコンテキスト内に存在しません。
です
dataGridView_ComicDataは作ってあります
ちなみにクラスは別ファイルです
よろしくお願いします