Results 1 to 9 of 9

Thread: Help please! Filtering datatable filled by excel file. [Resolved]

  1. #1

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Resolved Help please! Filtering datatable filled by excel file. [Resolved]

    Hi there,

    I have a problem which i cant find the solution in this forum(or i am crap at searching)

    I have uploaded my project ....i need the datagrid to be filtered according to what i type in the text boxes...

    any advice?
    Attached Files Attached Files
    Last edited by dinosaur_uk; Jun 16th, 2005 at 10:11 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help please! Filtering datatable filled by excel file.

    Without having read your code, I'd say the best way to filter is to use a DataView. You can bind to a DataView just like a DataTable. In fact, it may be the case that binding to a DataTable actually binds to that table's DefaultView. I'm sure there are others more knowledgeable than I who will confirm or deny this.

  3. #3

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: Help please! Filtering datatable filled by excel file.

    I have tried using a dataview...but have no idea where to start

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help please! Filtering datatable filled by excel file.

    A DataView behaves more like a DataRowCollection than a DataTable. As an example, to access the first row in a DataTable you would use myDataTable.Rows(0). The Rows property of a DataTable is a DataRowCollection. To access the first row of a DataView you would use myDataView(0). A DataView contains DataRowView objects, which are very similar to DataRows but not the same.

    You can create a DataView for a DataTable like this:
    VB Code:
    1. Dim myDataView As New DataView(myDataTable)
    or you can simply refer to the DefaultView property of the DataTable. The properties of most interest I think would be RowFilter, RowStateFilter and Sort.

    RowFilter can be set to a valid SQL "where" clause to have the the view only expose the rows that match those criteria, e.g.
    VB Code:
    1. myDataView.RowFilter = "ID > 100 AND Name LIKE 's%'"

    RowStateFilter can be used to hide rows that do not match a certain state or states, e.g. Added, Deleted, etc.

    Sort can be set to a valid SQL "order by" clause to order the visible rows on various fields, e.g.
    VB Code:
    1. myDataView.Sort = "ID DESC, Name ASC"

    I've never used one, but a DataViewManager is to a DataSet as a DataView is to a DataTable.

  5. #5

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: Help please! Filtering datatable filled by excel file.

    Lost

    I cant get it to work on my appl

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help please! Filtering datatable filled by excel file.

    DataViews exist specifically to filter DataTables so unless you want to write some really complex code to do it all manually I'd say you're going to have to come to grips with it. Feel free (obviously) to post any specific questions or sections of code that are causing you trouble.

    Good luck.

  7. #7

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: Help please! Filtering datatable filled by excel file.

    Wow ! it is remarkably easy to use!

    I will post my solution up when i tidy it up!

    Cheers !

  8. #8

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: Help please! Filtering datatable filled by excel file.

    Here it is....nice and easy
    Attached Files Attached Files

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help please! Filtering datatable filled by excel file. [Resolved]

    The sweet smell of success

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width