Merhaba arkadaşlar bu makalemizde CSV dosyasındaki
verileri datagridview nesnesinde göstereceğiz. Aşağıdaki şekildeki gibi bir CSV
dosyamız olsun. İlk önce CSV dosyamızdaki ilk satırı header olarak
tanımlıyoruz.
Şekil 1
Şekil 2
Form1.cs
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 datagridview_read_csv_file
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender,
EventArgs e)
{
string filePath = "D:\\customers.csv";
DataTable dt = new DataTable();
string[] rows =
System.IO.File.ReadAllLines(filePath);
if (rows.Length
> 0)
{
// the first
row is assigned as the column header in dataGridView
// dgview de
ilk satiri header atiyoruz.
string firstRow =
rows[0];
string[] headers =
firstRow.Split(',');
foreach (string header in headers)
{
dt.Columns.Add(new DataColumn(header));
}
// we get the
data from the csv file
// verileri
csv den aliyoruz
for (int i = 1; i < rows.Length; i++)
{
string[] records =
rows[i].Split(',');
DataRow
dr = dt.NewRow();
int columnIndex =
0;
foreach (string data in headers)
{
dr[data] = records[columnIndex++];
}
dt.Rows.Add(dr);
}
}
if
(dt.Rows.Count > 0)
{
dataGridView1.DataSource
= dt;
}
}
}
}
Bir
makalenin daha sonuna geldik. Bir sonraki makalede görüşmek üzere. Bahadır
ŞAHİN


4 comments:
If simplicity matters, Gamezy offers a clean interface and easy navigation. The process to obtain a Cricket ID is straightforward, making it suitable for both new and experienced users. With transparent details about deposits and withdrawals, the platform helps users stay in control while enjoying sports and casino games.
A reliable option for online cricket betting, Reddy Anna allows users to easily obtain a Cricket ID and start exploring features. The site shares helpful details about deposits and withdrawals, ensuring users feel confident while using it. With regular updates and a user-friendly interface, it creates a smooth experience.
The user-friendly structure of ReddyBook makes it a great choice for beginners and experienced users alike. The website provides clear guidance on deposits, withdrawals, and account setup. If you are searching for a reliable ReddyBook, this site offers consistent support. It also simplifies how to get your Cricket ID, helping users begin their betting journey easily.
Getting started with betting becomes easier through the sky exchange login, where users can quickly access their Cricket ID. The platform clearly explains deposits and withdrawals, helping users understand each step without confusion. It also provides helpful updates so users can stay aware of their account activities. The simple layout makes navigation easy for everyone. With a dependable Cricket ID, users can explore sports betting and casino games in a structured and convenient way.
Yorum Gönder