CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Location
    Galway, Ireland
    Posts
    96

    Sorting DataGrid when datasource is a DataSet

    I have a MyDataSet : DataSet class which contains 3 talbes and 2 data relations. This is set to a custom datagrid which can expand to show something like Users -> tickets for user -> details of ticket. I'm sure this is entirely simple, but how do I sort while keeping my dataset as the datasource? When I google they always discard the dataset and do something like:
    Code:
    MyDataSet ds = (MyDataSet) _dgUsers.DataSource;
    DataView dv = ds.Tables[0].DefaultView;
    dv.Sort = "something ASC";
    _dgUsers.DataSource = dv;
    _dgUsers.DataBind();
    This is useless as I've just lost my dataset. I tried modifying the view of the table inside the dataset but it just gets ignored (although it remains set when I sort again):
    Code:
    MyDataSet ds = (MyDataSet) _dgUsers.DataSource;
    DataView dv = ds.Tables[0].DefaultView;
    dv.Sort = "something ASC";
    _dgUsers.DataSource = ds;
    _dgUsers.DataBind();
    How should it be done? When I clone the DataSet it seems to work. Why is that?
    Lounge One-Eleven Presents: Gong! v2.0 - you never knew you needed it until you lived without it

  2. #2
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Sorting DataGrid when datasource is a DataSet

    If the grid is bound directly to the table, then you must implement the sorting in the grid. Typically we impl sorting in an intermediary such as a BindingContext (ADO.NET 2.0) that sits between the grid and the data
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

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

Featured