searching in datagridview using textbox

I had a datagridview which contains all the last name of a certain database.the data was displaying properly .I want to accomplished two tasks,first I want it that upon loading on the datagrid, data are sorted alphabetically already even without pressing the column header.Second I want to search the datagrid using a text box. I want like an autocomplete manner, if I type a single letter, say "B", the datagridcolumn will automatically point to the the name say "Bal" and so on...thanks once again.


Answer this question

searching in datagridview using textbox

  • Ying Fa

    anyone please

  • Rockdrala

    Sorry I have same problem (in datagridview and listbox) Have you decided this problem
  • claudioe

    thanks Ken for your reply....I need more specific approach please....

  • MVP User

    If you have a bindingsource, i'd use the following:

    Bindingsource.find returns an integer (row number) of the matching record

    Try

    Dim x As Integer = Me.CustomersBindingSource.Find("ColumnName", TextBox.Text)

    Me.CustomersBindingSource.Position = x

    Catch ex As Exception

    MsgBox("Search Value not Found")

    End Try

    Its pretty simple :)


  • pEri

    Here is what I would recommend:
    • Bind your DataGridView to a DataView (instead of a DataTable).
    • On Form.Load(), set your DataView.Sort property to the desired sort.
    • On TextBox.TextChanged(), set your DataView.RowFilter property to something like this: String.Format("ColumnName LIKE '{0}%'", TextBox.Text).
    Hope that helps,


  • Joe Morel - MSFT

    Lets say for example you are searching the first name column.

    dv.sort="FirstName"
    dim intRowNum as integer
    intRowNum=dv.find("Joe")

    ' Now we need to move to the right row
    MyBindingNavigator.BindingContext.Postion = intRowNum


  • Greg1970

    Assuming you are bound to a dataview named dv

    dv.Sort="MyColumnNameToSort"


  • ScottW1

    thanks RayV, would you be kind enough to elaborate on your second suggestion how can i set the dataview.sort property, say my dataview name is "Name" thanks...

  • searching in datagridview using textbox