473,569 Members | 2,601 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Search Grid with .NET DataGrid

I have a standard .NET DataGrid that is bound to a DataView. When the user
types into a text box above the DataGrid I issue the following code:

try
{
// We need to search for whatever the user is typing based on the type of
search ...
if (this.txtValue. Text.Length == 0)
{
this.UnHighligh tRow();
return;
}

if (this.cbSrhBy.S electedIndex.Eq uals(3))
return;

string lcSort = this.SrchFields[cbSrhOn.Selecte dIndex].ToString().Tri m(),
lcValue = this.ConvertVal ue(this.txtValu e.Text.Trim());
DataRow[] laRows = null;

switch (this.cbSrhBy.S electedIndex)
{
case 0: // Start of Field
if (lcValue.IndexO f("'").Equals (-1))
lcValue += "%";
else
lcValue = lcValue.Insert( lcValue.Length - 1, "%");

laRows = this.dsSearch.T ables[0].Select(lcSort + " LIKE " + lcValue,
lcSort);

break;

case 1: // Exact Phrase
laRows = this.dsSearch.T ables[0].Select(lcSort + " = " + lcValue, lcSort);

break;

case 2: // Any Part of Field
if (lcValue.IndexO f("'").Equals (-1))
lcValue = "%" + lcValue + "%";
else
lcValue = lcValue.Insert( lcValue.Length - 1, "%").Insert (1, "%");

laRows = this.dsSearch.T ables[0].Select(lcSort + " LIKE " + lcValue,
lcSort);

break;

case 3: // Filter Results
return;
}

if (laRows == null || laRows.Length.E quals(0))
return;

DataView loView = this.dsSearch.T ables[0].DefaultView;

this.UnHighligh tRow();
this.dataGrid_R esults.CurrentR owIndex = loView.Find(laR ows[0][lcSort]);
this.HighlightR ow();

this.txtValue.F ocus();
}
catch (Exception loExcep)
{
SharedCode.Erro rMessage(loExce p.ToString());
}

This UnHighlightRow and HighlightRow simply issue Unselect() and Select() on
the CurrentRowIndex .

What happens is when I search on a particular value, like let's say
"Last_Name" and I type in "SMI", it will go to the Smith's but it may not
choose the first one that is shown in the DataGrid when the Find() method is
issued. Why?

Mike
Nov 16 '05 #1
0 1157

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4322
by: Job Lot | last post by:
My DataGrid is bound to DataSet which contains relationship between two tables as follows: SqlHelper.FillDataset(strConn, CommandType.StoredProcedure, "spSelectClientApplicant", ds, New String() {"Client", "Applicant"}) ds.Relations.Add("Applicants", ds.Tables("Client").Columns("Client_ID"), ds.Tables("Applicant").Columns("Client_ID")) ...
3
1364
by: serge calderara | last post by:
Dear all, I am using a datagrid which is populate from an array list items This array list can be updated at anytime.If this occurs I need that the content of the datagrid get synchronise too. The problem I have is that if I clear the all datagrid, and update it to the new array list content, it might happen that I can see my grid...
2
1075
by: Sriram | last post by:
Hi, i am developing a search page, basically using datagrid. i have given a column as hyperlink so that when the user clicks on it, it gives the details of the selected item in a seperate page. But i want to add a feature so that it saves the search results. for example even after seeing an item the user should be able to still view the...
1
6495
by: Linda | last post by:
Hi, I'm new to asp.net and tryign to learn how to work with data grids. I'm retrieving data from a stored procedure and putting it in a data grid. I then want to be able to sort the data when clicking on the headers, using the Sub grdList_SortCommand. When clicking a header I get the error message: "System.Data.DataException: DataTable...
3
2202
by: pmud | last post by:
Hi, I have a web page (asp.net, code:c#). I havean html table with text boxes. Based on the user input , records are displayed in the data grid below it. Now the datagrid has a large no. of columns. & depending on what the user enters, the data grid can grow very large. So to avoid scrolling the whole page, I just want the data grid to be...
4
4471
by: Girish | last post by:
Im trying to create a grid within a grid programmatically. Ive been successful in doing this but I need the embedded grid to fire its ItemDataBound event so I can handle it. The event does not seem to fire for some reason. The code is below. Look towards the end of the CustomerDataGrid_OnItemDataBound(object sender, DataGridItemEventArgs e)...
9
2741
by: thebison | last post by:
Hi all, I hope someone can help with this relatively simple problem. I am building a timesheet application using ASP.NET C# with Visual Studio 2003.As it is only a protoype application, my database has been made in MSDE. I have a 'View Resources' page, the purpose of which is to show all employees, taken from that table in the database....
0
2067
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the end of this message, but I will start with an overview of the problem. I've made a content management solution for my work with a decently...
0
2712
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only, cannot serch by combine 3 table) Example I have the query table below, how do I make the code to seach based on the query from this: SELECT...
0
7615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7677
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.