This is a migrated thread and some comments may be shown as answers.

How to seach for text in a column

6 Answers 394 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Finn
Top achievements
Rank 1
Finn asked on 03 Jul 2008, 11:44 PM
Is there a simple way to search a column for a specified text and then select the first (then next) row with the text, if found?

(I am aware of the Filter functionality, but that is not what I need here.)

I'm having a hard time adjusting to the object model of the RadGrid, being used to such simple things as MSFlexGrid.TextMatrix(iRow, iCol).

Can you point me to a grahic view of the RadGrid object model?

Finn

6 Answers, 1 is accepted

Sort by
0
Accepted
Julian Benkov
Telerik team
answered on 04 Jul 2008, 01:43 PM
Hi Finn,

We currently do not provide text search operation directly in RadGridView. This nice new feature will be included after our Q2 release planned for end of month.

You can use Rows collection of RadGridView for linear search text operation:

private GridViewDataRowInfo FindRow(string text, string columnName) 
    foreach (GridViewDataRowInfo row in this.radGridView1.Rows) 
    { 
        if (text.Equals(row.Cells[columnName].Value.ToString(), StringComparison.InvariantCulture)) 
        { 
            return row; 
        } 
    } 
 
    return null

I will be glad to help you further if needed!

Regards,
Julian Benkov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Finn
Top achievements
Rank 1
answered on 04 Jul 2008, 06:32 PM
Thank you very much!
 I can't believe I missed the .Cell property.

Here's my crude VB solution:

Dim sFindMe As String

sFindMe = InputBox(

"Enter variable name:", "Search")

If sFindMe = "" Then Exit Sub

Dim bFound As Boolean

Dim iVariableColumn As Short

Dim radRow As Telerik.WinControls.UI.GridViewRowInfo

With RadGridView1

'Locate Variable column

iVariableColumn = .Columns.Item(

"Variable").Index

For Each radRow In .Rows

If InStr(1, radRow.Cells(iVariableColumn).Value.ToString, sFindMe, CompareMethod.Text) > 0 Then

radRow.IsCurrent =

True

radRow.EnsureVisible()

bFound =

True

Exit For

End If

Next radRow

If Not bFound Then MsgBox(sFindMe & " not found!")

End With

0
William
Top achievements
Rank 1
answered on 19 Nov 2008, 02:42 PM
Is there a "new and impoved" way of searching for text in a row and then selecting that row?  Or is the best way to loop the rows?

Thanks
0
Nick
Telerik team
answered on 20 Nov 2008, 04:09 PM
Hi William,

Thank you for your question.

There is no better way for iterating through rows. Use IsSelected to make rows selected/not selected and IsCurrent to set the current row. There can be more than one selected and only one current (a row can be selected and current). The current row is related to keyboard support and is visualized like a selected one. So in your case you want to make a single row both current and selected, and all other rows not selected.

Do not hesitate to write me back if you have more questions.

 
Regards,
Nick
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Eric
Top achievements
Rank 1
answered on 20 Oct 2011, 07:17 PM
Here is my vote for an improved column search.  It seems you are very close to having completed the underlying code if you look at your Excel-like drop down filter.  Specifically, the feature I'm looking for is for a quick - as you type string match (much like the Visual Studio "Incremental Search").  In our scenario, we have a grid with a potentially large set of data.  All cells are read-only so it would be nice to allow users to just start typing in the work they are searching for.  Probably not a big deal for us to implement using some of the suggestions above, but I wanted to raise this as a cool feature for the RadGridView.
0
Martin Vasilev
Telerik team
answered on 24 Oct 2011, 03:01 PM
Hello Eric,

Thank you very much for your suggestion.

We will definitely consider creating built-in search capabilities if more customers ask for the same feature. For the time being, I believe there are couple of ways to implement most of the possible specific requirements by using currently the available functionality and API. 

Please let me know if you need any assistance to achieve your goal. I will be glad to help you. 

Best wishes,
Martin Vasilev
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

Tags
GridView
Asked by
Finn
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Finn
Top achievements
Rank 1
William
Top achievements
Rank 1
Nick
Telerik team
Eric
Top achievements
Rank 1
Martin Vasilev
Telerik team
Share this question
or