C# - Populate Datagridview With Files Name's

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; 

        }
    }
}

      
///////////////OUTPUT:





c# fill datagridview with file name's




Share this

Related Posts

Previous
Next Post »

2 comments

comments
20 décembre 2019 à 20:53 delete

code is working finely but how i will it ascending order or descending order?

Reply
avatar