RadGrid sorting and dataset sorting

14 posts, 0 answers
  1. John Kok
    John Kok avatar
    9 posts
    Member since:
    Oct 2009

    Posted 20 Feb 2010 Link to this post

    I have a radgridview which is bound to a dataset.
    When the user sorts the radgrid, the dataset is not sorted equally so it does not give the correct data back for editing.

    Is there a solution to that ?
  2. Nick
    Admin
    Nick avatar
    767 posts

    Posted 22 Feb 2010 Link to this post

    Hi John Kok,

    Thank you for contacting us. Well, the data is sorted internally in the grid only for presentation purposes, but that sorting cannot apply to your data source as well. Please extend on your scenario. Perhaps you can just access the data through the grid where it is sorted. You can find examples in our documentation.

    Best wishes,
    Nick
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jonah
    Jonah avatar
    1 posts
    Member since:
    Mar 2011

    Posted 23 Mar 2011 Link to this post

    Hi,
    I have a similar requirement. Here's the scenario.
    1. User sorts by one or many columns on the grid.
    2. The user requests to print to PDF.
    3. The PDF prints while preserving the sort order specified by the user.

    Previously, we used a standard GridView and simply sorted the DataSet before binding to the GridView. It was then easy to print according to the order of the DataSet displayed by the GridView. How can we accomplish this using RadGrid?

    Thanks,
    Jonah
  5. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 25 Mar 2011 Link to this post

    Hello Jonah,

    Sadly i do not understand the problem here, once the user has sorted the grid in any way required, you can just export that grid as is, and the exported data will be sorted and display just the way it was in the grid.

    Please take a look at this help article on exporting data using RadGridView

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga
    Telerik WinForms MVP
  6. Raj
    Raj avatar
    10 posts
    Member since:
    Mar 2012

    Posted 19 Apr 2012 Link to this post

    Hi,
    I am sorting the radgrid after sorting the data in dataset is not sorting,

    I have a scenario for this iam adding new rows form grid,new rows are updating to dataset.(there is no Datakey for thease records)
    after sorting,issue comes with deleting,i need to delete record for that iam using e.item.datasetindex which is pointing to diff record in dataset.

    Please help me how to fix this issue.

    Thanks,
    Raj
  7. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 23 Apr 2012 Link to this post

    Hi Raj,

    Thank you for writing.

    You can delete the record using the DataBoundItem property of GridViewRowInfo instance. The DataBoundItem can be cast to DataRowView and then you can get the reference to DataRow item. Here is a sample example using CurrentRow of RadGridView:
    protected override void OnButton1Click()
    {
        DataRowView rowView = gridView.CurrentRow.DataBoundItem as DataRowView;
        rowView.DataView.Table.Rows.Remove(rowView.Row);
    }

    The proposed approach, makes this manipulation universal, so it will not matter if the grid is sorted or filtered.

    I hope this helps.

    All the best,
    Julian Benkov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  8. Raj
    Raj avatar
    10 posts
    Member since:
    Mar 2012

    Posted 23 Apr 2012 Link to this post

    Hi,
    Thanks for your reply.

    The above is not working for me iam using Wed Radgrid.i didnt find any

     

     

    DataRowView rowView = radgrid.DataBoundItem as DataRowView;

     


    Below is my sample code.

     

     

    protected void radgrid_DeleteCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)

     

    {

    oCashDetailDS.Tables[

     

    "table1"].Rows.RemoveAt(e.Item.DataSetIndex);

     

    }

    With out sorting its working fine but after sorting e.Item.DataSetIndex producing dataset index, but it is not equavalent main dataset datasetindex with this deleting diff record in Main Dataset.

    Same e.item.datasetindex using for Updating the record also.

    Please help me out with this issue.

    Thanks,
    raj

  9. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 26 Apr 2012 Link to this post

    Hi Raj,

    Please note that this forum concerns RadGridView for WinForms rather than RadGrid for ASP.NET AJAX. Please address your question in the appropriate forum (http://www.telerik.com/community/forums/aspnet-ajax/grid.aspx) so the corresponding team can handle it.
     
    All the best,
    Stefan
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  10. Emil
    Emil avatar
    19 posts
    Member since:
    Oct 2012

    Posted 19 Jan 2013 Link to this post

    Raj, have you found a solution? I'm having the same problem.
  11. Emil
    Emil avatar
    19 posts
    Member since:
    Oct 2012

    Posted 22 Jan 2013 Link to this post

    I got it to work (delete the row from the DataTable after the Grid si sorted). I'm using the ViewState to save the DataTable.

    Protected Sub RadGrid1_DeleteCommand(sender As Object, e As GridCommandEventArgs) Handles RadGrid1.DeleteCommand
         Dim dtRecords As DataTable = DirectCast(ViewState("dtBooks"), DataTable)
         dtRecords.Rows.Clear()
     
         For Each col As GridColumn In RadGrid1.Columns
             Dim colString As New DataColumn(col.UniqueName)
             dtRecords.Columns.Add(colString)
         Next
         For Each row As GridDataItem In RadGrid1.MasterTableView.Items
             'loops through each rows in RadGrid
             Dim dr As DataRow = dtRecords.NewRow()
             For Each col As GridColumn In RadGrid1.MasterTableView.AutoGeneratedColumns
              'loops through each AutoGenerated column in RadGrid
              dr(col.UniqueName) = row(col.UniqueName).Text
             Next
             dtRecords.Rows.Add(dr)
         Next
     
         RadGrid1.DataSource = dtRecords
         RadGrid1.DataBind()
     
         Dim rowID As Integer = e.Item.DataSetIndex
         Dim dt As DataTable = DirectCast(ViewState("dtBooks"), DataTable)
         dt.Rows.Remove(dt.Rows(rowID))
         ViewState("dtBooks") = dt
         RadGrid1.DataSource = dt
         RadGrid1.DataBind()
    End Sub
  12. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 25 Jan 2013 Link to this post

    As I mentioned this forum concerns RadControls for WinForms and I would kindly ask you once again to use the ASP.NET AJAX forums for your questions regarding the ASP.NET AJAX Grid.
     
    Greetings,
    Stefan
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  13. vahid
    vahid avatar
    7 posts
    Member since:
    May 2016

    Posted 02 Jun in reply to Stefan Link to this post

    Hi

    I have same issue when user sort 1 or 2 columns in Radgridview Winform the grid does not return correct value for current row.

    I need whenever user scrolling in grid one filed shows in a  separate text box but after sorting the grid it does not return right row index

     

  14. vahid
    vahid avatar
    7 posts
    Member since:
    May 2016

    Posted 02 Jun in reply to Stefan Link to this post

    Hi
    I have same issue when user sort 1 or 2 columns in Radgridview Winform the grid does not return correct value for current row.
    I need whenever user scrolling in grid one filed shows in a  separate text box but after sorting the grid it does not return right row index
  15. Dimitar
    Admin
    Dimitar avatar
    1414 posts

    Posted 03 Jun Link to this post

    Hi Vahid,

    Thank you for writing.

    The following article shows why you are not getting the expected index: Rows vs ChildRows.

    In addition, you can get the field or the data item directly from the row instance, there is no need to use indexes:
    private void RadButton1_Click(object sender, EventArgs e)
    {
        Console.WriteLine(radGridView1.CurrentRow.Cells["Name"].Value);
     
        DataRow data = ((DataRowView)radGridView1.CurrentRow.DataBoundItem).Row;
        Console.WriteLine(data["Name"]);
        
    }

    I hope this will be useful. 

    Regards,
    Dimitar
    Telerik
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready