How to filtering data in a datagrid dynamically?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Toshi Trivedi
    New Member
    • Jan 2011
    • 13

    How to filtering data in a datagrid dynamically?

    Hi,

    I am using a data grid which is filled up with the data from the table. I have given two choices to the user. One a combobox is given having four columns in the list from which user can select a column name. Second a text box is given in which he can type the value. Based on the values of the column name and value i want to filter out records in the data grid. But don't know how. I am not using dataset only data grid is filled up directly from the table.

    Please help me.

    Thanks in advance
  • bentleyw
    New Member
    • Feb 2008
    • 32

    #2
    If you have a DataTable as your DataSource for the DataGridView, and you want to sort or filter the list, one way would be to use a DataView. Here is an MSDN page with an example of how to do it:



    Basically what you'd be doing is creating a view of the table data and setting the RowFilter property to be like the "where" clause of a SQL statement. Then you can use the DataView as the DataSource for the grid instead of the DataTable.

    Comment

    • Toshi Trivedi
      New Member
      • Jan 2011
      • 13

      #3
      Thanks a lot bentleyw

      Comment

      • bentleyw
        New Member
        • Feb 2008
        • 32

        #4
        No worries. Glad to help.

        Comment

        Working...