开发者

c# Windows application add file into datagrid control

开发者 https://www.devze.com 2023-02-13 04:19 出处:网络
I want to search all files in particular folder and add those files into data grid view in C#. I have two 开发者_开发技巧text box and two buttons. The first button browse the folder and textbox1selec

I want to search all files in particular folder and add those files into data grid view in C#. I have two 开发者_开发技巧text box and two buttons. The first button browse the folder and textbox1 select folder path and textbox2 want search all the doc files click on second button and add the files into datagridview. plz help me.


Here is my guess at what you're looking for:

//Assume that textbox1 has folder path
DataGridView1.DataSource = Directory.GetFiles(textbox1.Text);


 OpenFileDialog openFileDialog = new OpenFileDialog();
                    openFileDialog.Multiselect = true;
                    openFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
                    openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                    if(openFileDialog.ShowDialog() == true)
                    {
                            foreach(string filename in openFileDialog.FileNames)
                                    datagrid.Items.Add(Path.GetFileName(filename));
                    }
0

精彩评论

暂无评论...
验证码 换一张
取 消