-->

Thursday, June 6, 2013

How to bind GridView with search results in c# Windows Forms

How to bind GridView with search results in c# Windows Forms

There are many cases in which user want to search some records in database that are satisfying a condition and bind them to gridview. So I am writing this post to bind a gridview with search option and in else case all the data from database will bind to gridview.

Now create a new windows form application in visual studio, make a database as I have described in my previous post How to create Database using Entity Framework and add a table i.e. Student having following properties:

bind GridView with search results
Insert some records in Student table as I have entered following list of items:
Add item to the list
In Form1 designer add two controls TextBox and DataGridView.
Now bind DataGridView to a list that have all the records saved in student table in database.
There is an event of textbox i.e. textchanged event that is raised when the value of text property is changed on control.
In this event of textbox write the following code:
binding data from data list
When you run this project it will show default binding of datagridview as
output screen of the binding data from data list

and when you type some text in textbox then:
searching result of  control
so this datagridview has been bind to search result of textbox.
Download Example.

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved