Click here to Skip to main content
13,087,566 members (92,591 online)
Rate this:
Please Sign up or sign in to vote.
I am developing an application for which i have included seach files in given folder one like in Windows 7 start menu. in which i want to search it on Textbox_TextChanged Event but i dont know whether i need to fire any query on anything. Please tell me what should i do?

I have to show result in DataGridView and any file type with extension. result should change on Textbox_TextChanged
Posted 5-Apr-12 23:59pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

In the Visual Studio designer, highlight your TextBox.
Look at the Properties pane.
Click the button that looks like a lightning bolt - that will show you the Events instead of the Properties.
Scroll down to TextChanged. Double click it.
That will hook up an event handler for you, and take you to the method that is called when the user changes the text in the text box.

You can now write your code in the method - when the user types in the TextBox, that method will be called for each character.
javedsmart 6-Apr-12 6:14am
I think you have not read the question correctly.
I know how to get TextChange event i want to know how i can search files in folder and show result in DataFridView.
OriginalGriff 6-Apr-12 6:27am
I think you've not written it properly! :laugh:
What bit is giving trouble? What is the users input supposed to do when it changes?
(Remember I can't see your screen, so anything you don't tell me I have to make up...)
javedsmart 9-Apr-12 2:49am
:-) Sorry OriginalGriff for late reply.
Actually all i want is show all files in DataGridView as i enter text in TextBox and show all related files in DataGridView from all drives. Same as in Windows 7 Start Menu search which shows all related files from complete drive.
OriginalGriff 9-Apr-12 4:36am
Oh boy! Not a simple request at all!
I've not tried to do this, but if you are after similar functionality to the Start menu textbox, then you will have to do some reading:
Good luck! I don't think this is a ten minute job... :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

The first thing to do is add this to the using section if not there already:
using System.IO;
using System.Data;

To get the files from a folder, you can use:
string[] foundFiles = Directory.GetFiles(thePathVariable, theSearchBoxText + "*.*");

You have to change "thePathVariable" and "theSearchBoxText" to suite your needs.
By appending the wildcard string ("*.*") you're searching for every file with any extension that starts with the text written in your search box. You can play with the wildcards to achieve any other needs.

To display the results into a datagridview, we have to transfer the data from the string array to a datatable. This can be also achieved easily with LINQ, but seems you're not quite there, so:

DataTable s = new DataTable();
foreach (string aFile in foundFiles)
dataGridView1.DataSource = s;

And that's it, hope it helps.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 9 Apr 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100