In previous two parts, I covered some basic DataGrid operations. I am extending the functionality of DataGrid by adding a search option to it as part 3 of this series.
Here are first two parts:
DataGrid Customization Part 1
DataGrid Customization Part 2
In the third part of this series, I will show you how you can implement search feature in a DataGrid. I have divided search feature in two categories - server side search and client side search.
Why two types of search? OK, first of all let me tell you what I mean by server side searching and client side searching.
There are two common ways to search in a data-bound DataGrid, when data is being filled from a database. First, you can request only data you want by using the WHERE clause in a SELECT statement, fill a DataSet using this SQL SELECT statement and bind data. You need to request data every time you search for a keyword, which means make sure connection is open, create a DataAdapter and call Fill method of DataAdapter to fill a DataSet and bind DataSet to the DataGrid. This scenario is required when multiple users are updating data simultaneously.
Now think about a different situation where there are no data updation. Whatever data you had in your database when you connected first time will be the only data. In this scenario, requesting data from database every time you search for a keyword is not feasible. Think about a store, where store manager updates the store once in a month. In this case, client side search is a better option. Both DataTable and DataView provides methods and properties to filter the data. You can either use the Select method of DataTable or RowFilter of DataView. In our case, we already have a DataView, which is bound to the DataGrid, we will use RowFilter property of DataView.
OK, now let's put these things together.
I am adding a label, a text box, and a check box to the existing form of Part 2. I also add a new menu item to the DataGrid right click menu called "Find". The final form looks like the Figure 1.

Figure 1. Customized DataGrid


Bilam MondalPosted May 5, 2016, 1:31 AM
Thanks Mahesh simple way to understabd...
Praveen Kumar DubeyPosted Dec 22, 2012, 6:06 AM
Thanks Mahesh Chand ji............