views:

146

answers:

1

Hello all,

I cannot seem to be able to find a way to do a full text search on a databound DataGridView control across the entire breath of its columns and rows.

The DataTable and DataView objects seems to force me into searching for specific columns either through Select(), Find(), or FindRows(). Same with the DataGridView control.

I have one search string and I need to run it against the whole contents of the DataGridView. I'm sure the answer lies somewhere close. But I cannot seem to be able to find it at this stage in my apprenticeship of C# and the .Net framework.


This is my current solution which I would like to avoid:

/*...*/

for (int i = found_last_row + 1; i < dataGridRes.Rows.Count; ++i)
{
    for (int j = 0; j < dataGridRes.Columns.Count; j++) 
    {
        if(dataGridRes.Rows[i].Cells[j].Value.ToString().Contains(search_last_str.))
        {
            dataGridRes.Rows[i].Selected = true;
            dataGridRes.FirstDisplayedScrollingRowIndex = i;

            found_last_row = i;
            break;
        }
    }
}

/* ...*/
A: 

I think the common approach is to search the source data (not the grid), then re-bind to only show the matches. If you use paging, the grid pulls the data page by page from the database, so you would only be searching the page that you currently see.

cdonner
Yes. That would be a possible solution. But searching the DataTable or DataView objects forces me to search for specific columns, which is not what I want to do. I don't need to rebind either since I only wish to locate and select the row and not filter them.
Krugar