开发者

c# Windows application add file into datagrid control

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜