Hi
I need help in gridview Control Search.
I have a gridview control with nearly 4000 records. I am using a textbox to enter a search string to search for a match in the gridview records. If there is a match of that word is find in the gridview control either cursor has to point to that record or that particular record should be highlighted with some color say yellow. If more than one record is found with that string, obviously the pointer should be on the first record having match or highlight the first record that is having matching string.
If we can use 'find Next' like in MS-Word, that will be great too.
If there is any idea from anybody, will be a great help. Thank you.
Prasad
Loading
Prasad VempatiPosted May 27, 2010, 8:06 PM
Thank you for the reply. I believe that, the Cell property in gridview does not refer to gridview row cell. It refers to table Cell.
That is the reason, when I use row.Cells[2].Text, it is not returning any text for comparision. Since the if statement failed, it goes to else statement and coloring all the gridview rows instead those rows having the search text.
Thank you
Prasad
PJ MartinsPosted May 27, 2010, 8:42 AM
private int _lastRowIndex = -1; // global variable for find next
bool rowFound = false;
foreach (GridViewRow row in GridView1.Rows)
{
if (row.Cells[0].Text == "<
{
row.BackColor = Color.Yellow;
_lastRowIndex = row.RowIndex;
rowFound = true;
break;
}
else
{
row.BackColor = Color.Yellow;
}
}
// reset last found index if nothing was found
if (!rowFound)
_lastRowIndex = -1;
Prasad VempatiPosted May 27, 2010, 2:09 AM
Thank you for your reply. The end user wants when particular row is having search string, the entire row should be either selected and colored or just a pointer points to that record.
Prasad
Prasad VempatiPosted May 27, 2010, 1:56 AM
Thank you for your reply. Here I am using gridview control. In gridview control I cannot access the cell value, like row.Cells[1].Value because there is no property like that. What is the other property that i can use which replaces the 'Value' property of the Cell ?
Thank you
Prasad
arshi patelPosted May 27, 2010, 12:55 AM
.. Hope may be useful
PJ MartinsPosted May 26, 2010, 4:11 PM
private int _lastRowIndex = -1; // global variable for find next
bool rowFound = false;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells["<
{
row.DefaultCellStyle.BackColor = Color.Yellow;
row.Selected = true;
_lastRowIndex = row.Index;
rowFound = true;
break;
}
else
{
row.DefaultCellStyle.BackColor = Color.White;
row.Selected = false;
}
}
// reset last found index if nothing was found
if (!rowFound)
_lastRowIndex = -1;