当前位置:网站首页>C reads the data in the CSV file and displays it after importing the DataTable
C reads the data in the CSV file and displays it after importing the DataTable
2022-07-28 20:39:00 【laocooon】
1 99 99 99
2 88 88 88
3 77 77 77
4 66 66 66
5 55 55 55
6 44 44 44
7 33 33 33
8 22 22 22
9 11 11 11
10 0 0 0
private void button4_Click(object sender, EventArgs e)
{
string fileName = string.Empty;
string strFilePath = System.IO.Directory.GetCurrentDirectory();
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = strFilePath;
openFileDialog.Filter = "(*.CSV)|*.CSV";
openFileDialog.Title = " Open data file ";
DialogResult result = openFileDialog.ShowDialog();
if (result != DialogResult.OK)
return;
List<string> listA=new List<string>();
List<string> listB = new List<string>();
List<string> listC = new List<string>();
fileName = openFileDialog.FileName;
using (var reader = new StreamReader(fileName))
{
while (!reader.EndOfStream)
{
var line= reader.ReadLine();
var values= line.Split('\t');
if (values.Length != 3)
{
MessageBox.Show(
" Not a legal data source , The program failed to import data ~!",
" Prompt information ",
MessageBoxButtons.OK,
MessageBoxIcon.Warning
);
return;
}
listA.Add(values[0]);
listB.Add(values[1]);
listC.Add(values[2]);
}
}
string[,] data = new string[listA.Count,3];
for (int i = 0; i < listA.Count; i++)
{
data[i,0] = listA[i];
data[i, 1] = listB[i];
data[i, 2] = listC[i];
Console.WriteLine($"{data[i, 0]} {data[i, 1]} {data[i, 2]}");
}
// Two dimensional array turn DataTable data source
DataTable dt = new DataTable();
for (int i = 0; i < data.GetLength(1); i++)
dt.Columns.Add(i.ToString(), typeof(int));
for (int i = 0; i < data.GetLength(0); i++)
{
DataRow dr = dt.NewRow();
for (int j = 0; j < data.GetLength(1); j++)
dr[j] = data[i, j];
dt.Rows.Add(dr);
}
dataGridView1.DataSource = dt;
}边栏推荐
- Configure Windows Server + install MySQL database on the server + Remote Access database
- Tree row expression
- 太空射击第14课: 玩家生命
- Three steps to teach you unity serial communication
- [POC - proof of concept]
- Raspberry pie creation self start service
- Commands related to obtaining administrator permissions
- C language data 3 (1)
- 根据openGauss/MogDB的lwtid查看线程堆栈。
- Raspberry Pie 3 connected to WiFi
猜你喜欢

Introduction to seven kinds of polling (practice link attached)

How to make the design of governance structure more flexible when the homogenization token is combined with NFT?

Raspberry pie 4B deploy yolov5 Lite using ncnn
![[task01: getting familiar with database and SQL]](/img/de/c1370461d8c2561c4dfd0ff5c7e830.png)
[task01: getting familiar with database and SQL]
![[C language] use function pointers to make a different calculator](/img/58/e6ba11e054d9e45ec979224ac3e4c6.png)
[C language] use function pointers to make a different calculator

Other IPS cannot connect to the local redis problem solving and redis installation

Solve the problem that the nocturnal simulator cannot access the Internet after setting an agent

One article makes you understand what typescript is

产品力大幅提升 新款福特探险者发布
![[detailed use of doccano data annotation]](/img/40/c18cf8d5519328d707ed89fccb70ee.png)
[detailed use of doccano data annotation]
随机推荐
Nocturnal simulator settings agent cannot be saved
UE4 3dui widget translucent rendering blur and ghosting problems
Mysql报错:Specified key was too long; max key length is 767 bytes
Anaconda creation environment
Voice controlled robot based on ROS (II): implementation of upper computer
Soft raid
Who cares about the safety of the battery when it ignites in a collision? SAIC GM has something to say
一文了解 Rainbond 云原生应用管理平台
Redis 3.0源码分析-数据结构与对象 SDS LIST DICT
Raspberry pie 4B uses MNN to deploy yolov5 Lite
Torch. NN. Linear() function
LeetCode_位运算_中等_260.只出现一次的数字 III
User, user group related operations
Read JSON configuration file to realize data-driven testing
[link url]
Solve the problem that the nocturnal simulator cannot access the Internet after setting an agent
微信公众号授权登录后报redirect_uri参数错误的问题
上海交大牵手淘宝成立媒体计算实验室:推动视频超分等关键技术发展
树行表达方式
Raspberrypico analytic PWM