How To Fill DataGridView With Files Name From Folder Values On Another Form Using C#
In This C# Tutorial We Will See How To Bind DataGridView File Name's Form Folder Using CSharp Programming Language.
Project Source Code:
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;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class DataGridView_With_Files_Name : Form
{
public DataGridView_With_Files_Name()
{
InitializeComponent();
}
private void DataGridView_With_Files_Name_Load(object sender, EventArgs e)
{
String[] files = Directory.GetFiles(@"C:\Users\samsng\Desktop\products");
DataTable table = new DataTable();
table.Columns.Add("File Name");
for(int i = 0; i < files.Length; i++)
{
FileInfo file = new FileInfo(files[i]);
table.Rows.Add(file.Name);
}
dataGridView1.DataSource = table;
}
}
}
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;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class DataGridView_With_Files_Name : Form
{
public DataGridView_With_Files_Name()
{
InitializeComponent();
}
private void DataGridView_With_Files_Name_Load(object sender, EventArgs e)
{
String[] files = Directory.GetFiles(@"C:\Users\samsng\Desktop\products");
DataTable table = new DataTable();
table.Columns.Add("File Name");
for(int i = 0; i < files.Length; i++)
{
FileInfo file = new FileInfo(files[i]);
table.Rows.Add(file.Name);
}
dataGridView1.DataSource = table;
}
}
}
///////////////OUTPUT:
2 comments
commentsnot working in vs 2010
Replycode is working finely but how i will it ascending order or descending order?
Reply