How to seach for text in a column

7 posts, 1 answers
  1. Finn
    Finn avatar
    27 posts
    Member since:
    Jun 2008

    Posted 03 Jul 2008 Link to this post

    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

  2. Answer
    Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 04 Jul 2008 Link to this post

    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
  3. Finn
    Finn avatar
    27 posts
    Member since:
    Jun 2008

    Posted 04 Jul 2008 Link to this post

    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

  4. William
    William avatar
    55 posts
    Member since:
    Sep 2008

    Posted 19 Nov 2008 Link to this post

    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
  5. Nick
    Admin
    Nick avatar
    767 posts

    Posted 20 Nov 2008 Link to this post

    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.
  6. Eric
    Eric avatar
    24 posts
    Member since:
    Jul 2011

    Posted 20 Oct 2011 Link to this post

    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.
  7. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 24 Oct 2011 Link to this post

    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.

Back to Top