Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 C#3.0 VB8.0 VB9.0 C# VB.NET , +
Hi,
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 6-Apr-12 0:59am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  
Rate this: bad
good
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.
  Permalink  
Comments
javedsmart at 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 at 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 at 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 at 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:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa965362(v=vs.85).aspx
Good luck! I don't think this is a ten minute job... :)
Rate this: bad
good
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();
s.Columns.Add("FileName");
 
foreach (string aFile in foundFiles)
{
   s.Rows.Add(aFile);
}
dataGridView1.DataSource = s;
 
And that's it, hope it helps.
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 9 Apr 2012
Copyright © CodeProject, 1999-2014
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