locked
C#: Winform - Filter on DataTable in DataGridView RRS feed

  • Question

  • I have made a service that sends a datatable with person information to a client. In the forms init event I call the service to retreive all persons from my service and displays them in a datagridview.

    In the form I want to be able to filter on e.g. first name. I have used the select method to filter on the datatable but it only returns datarows and not datatable which I need to set as datasource in my datagridview.

    Also I can not add the datarows returned from the select statement to add to another datatable as they belong to the first datatable I created.



    Does anyone know how I can solve this problem?

    Saturday, September 13, 2008 7:57 AM

Answers

  • Greetings,

    The way I prefer to approach the problem is to not do the work in the data grid itself. If you create an ADO.NET dataset and work within that I think you will find it easier. Retrieve the initial table through the select statement to a data table in the dataset. Then create a data view on that table and bind the data view to the data grid. The data view provides you with a lot of flexibility to sort and filter. The good news is that this allows you to makes through the data view to the original data table.

    Does this put you on the right track?

     

    Steve Smegner

    Application Development Consulting Group

     

    • Proposed as answer by Steve Smegner Tuesday, September 16, 2008 6:50 PM
    • Marked as answer by David DoBell Friday, September 26, 2008 4:03 PM
    Tuesday, September 16, 2008 6:50 PM

All replies

  •  Hi,

    This forum is to support questions on Open Specifications of Windows Protocols.

    There is a very helpful community of C# developers on the MSDN Development forum that may be able to assist you with your solution. I suggest you post your question to the C# Development forum found here:
    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/threads/

    You should also search the forums in case someone has already asked a similar question.
    SQL Server Data Services
    http://social.msdn.microsoft.com/Forums/en-US/category/sqlserverdataservices/
    MSDN
    http://social.msdn.microsoft.com/Forums/en-US/categories/

    Regards,
    Edgar

    Saturday, September 13, 2008 2:55 PM
    Moderator
  • Greetings,

    The way I prefer to approach the problem is to not do the work in the data grid itself. If you create an ADO.NET dataset and work within that I think you will find it easier. Retrieve the initial table through the select statement to a data table in the dataset. Then create a data view on that table and bind the data view to the data grid. The data view provides you with a lot of flexibility to sort and filter. The good news is that this allows you to makes through the data view to the original data table.

    Does this put you on the right track?

     

    Steve Smegner

    Application Development Consulting Group

     

    • Proposed as answer by Steve Smegner Tuesday, September 16, 2008 6:50 PM
    • Marked as answer by David DoBell Friday, September 26, 2008 4:03 PM
    Tuesday, September 16, 2008 6:50 PM