How to Implement Search in DataGridView in C# Visual Studio | Search and Filters in DataGridView C#

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys welcome to my Channel today in this video tutorial we are going to learn about implementing search in our data grid view in C sharp so let's start so uh first let me show you the application that we have created now if you can see that we have this data grid View and uh we have this student underscore ID and student name and this is student underscore's father name here now I want to change these uh columns names uh to student ID name and father name so to do this I will come to my um ssms and here we will modify this uh get student data stored procedure so we created this store procedure in our previous tutorial but we forgot to convert our rename this in these columns n or stored procedure so I'll make this student ID and uh as a name uh name is uh column here so student our name is perfect name as uh it should be in double quotes a single quotes uh double quotes so I'll use single quotes a single code angle code and here I'll answer you the single quote and father name and send record now I'll modify execute this to it will uh common completed successfully so is successfully modified now if I go again to our Visual Studio stop this and rerun this now you will see that the column names will change now you can see here student ID name and father name here now we are good to go now we will Implement search in this uh uh data grid view on this column name as well as on this District name we have to change this District name as well so I'll close this again go to this again and here I'll uh make this um District name as this trick and now I'll execute again so now it will be for effect so now I'll come here and add in a label and a text box so first I will search for a label so label and I'll put it here I'll rename this as uh text as search and I'll make the font bold okay and now I'll bring in a text box from text box and I'll place it here now I'll extend it a bit now I'll change the name here uh search text box and now all now it is perfect now I'll uh double click on this to create its uh text change event now here we will uh code so now we have a problem now you can see that this data table which is this data source of this um dvg student data grid view students so it is locally defined here here so now I want it Global so for that I will come here and uh I'll use here private um data table um STD data table equals new data table and I'll put semicolon here I'll close this and now I will go down and here we will remove this and here we will load it in the student data table STD data table and here we will assign it is TD data table now with this STD data table is accessible inside here so now here we will create data View DV that have your students equals STD data table dot default view semicolon and now here we will implement the search uh we will use DV DV students dot row filter it is not um DV students dot row filter this one equals and now we will use a cavity like we use in SQL server or in s cable so here we will use a name and this name is the column name and then like and then percent single quote first and then percent then Plus um name search text box Dot text and then Plus and then percent sign and then single coat and now we will put semicolon here now if we run this right now and now if I search here is a now you can see that it has a filtered all the names with SA or a when I use n so you can see that it filtered all the names with s a n and if I use ta so it has filtered all the name or searched or the name with da now we will Implement uh this search also on this District so for that I will close this and I'll create a new method here um or first I will go to design main form and I will drag in a new text box so if I search here three text box and I'll replace it here now I'll explain this and I'll move it above now it's okay now uh we will change its name so District search text box and now all double click on it to create its uh click event now we will create a new method and we will pass in this code into that and then we can search uh for both and that now I'll come here private search white and search bye column name and now we'll put curly braces now I'll copy this code from here Ctrl C this and I will Ctrl V it here now as we have this uh code copied now I will create two parameters here one string column name and the other one is text box txt so now um this name is column name so I'll remove this and here I'll use column column name Plus and here we will use txt instead of text box e x t now our code is complete so now we will call this uh method here search by a column name and we will pass in the parameters to this method so here the column name is a district and the text box name is uh District search text box and now we will similarly call this method here we will remove this code backspace and search by column name and I'll pass in here name is the column name and then uh text box so name search text box and I'll put semicolon now let's run it and check it if it is working so now if I search in this name column is a you can see it is filtering the name now if I search in this if I remove this and if I search in this uh District name if I show you the districts so here if I search now shehra you can see now Shara is filtered all the records with just ignore and if I search d i k now you can see the ik the record with Dak is filtered so in this way we can Implement search in our data grid view I think that's all for today I hope you like the video if you like the video please like subscribe and comment thank you
Info
Channel: Programming Guru
Views: 11,589
Rating: undefined out of 5
Keywords: How to Implement Search in Datagridview using C#, How to Implement Search in a Datagridview in C#, How to Implement Search in a DataGridView in c#, How to Implement Search in DatagridView with C#, Search and filters in datagridview c#, c# datagridview search, search in datagridview windows forms, c#, csharp, csharp tutorial for beginners, c# database programming, c# sql server, sql server and c#, search in datagridview, search data in datagridview c#, Filter data in datagridview c#
Id: B4hEG6xfCOE
Channel Id: undefined
Length: 12min 57sec (777 seconds)
Published: Wed Oct 05 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.