This is a migrated thread and some comments may be shown as answers.

RadGrid sorting and dataset sorting

13 Answers 513 Views
GridView
This is a migrated thread and some comments may be shown as answers.
John Kok
Top achievements
Rank 1
John Kok asked on 20 Feb 2010, 11:42 AM
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 ?

13 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 22 Feb 2010, 08:54 AM
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.
Jay
Top achievements
Rank 1
Iron
Iron
commented on 10 Jun 2023, 03:21 AM

Then the sort functionality of the grid is worthless. Why would you do that? Why would you not at least have a method that turns on mirroring the presentation view of the grid to the underlying data source? That just baffles me.
Dinko | Tech Support Engineer
Telerik team
commented on 13 Jun 2023, 09:48 AM

In general, you could disable the built-in data sorting operation by setting the this.radGridView1.MasterTemplate.DataView.BypassSort property to true. This way the UI indication, SortDescriptors, and events remain, and the sorting will be left to the developer in the SortChanged event handler. You could check the bottom section of the  Basic Sorting help article where this property is described.
0
Jonah
Top achievements
Rank 1
answered on 24 Mar 2011, 01:17 AM
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
0
Emanuel Varga
Top achievements
Rank 1
answered on 25 Mar 2011, 02:33 PM
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
Jay
Top achievements
Rank 1
Iron
Iron
commented on 10 Jun 2023, 03:22 AM

We don’t want to export the grid. We want our data source to reflect the presentation view of the grid.
0
Raj
Top achievements
Rank 1
answered on 19 Apr 2012, 10:11 PM
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
0
Julian Benkov
Telerik team
answered on 23 Apr 2012, 03:21 PM
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 >>
0
Raj
Top achievements
Rank 1
answered on 24 Apr 2012, 04:16 AM
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

0
Stefan
Telerik team
answered on 26 Apr 2012, 03:06 PM
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 >>
0
Emil
Top achievements
Rank 2
answered on 19 Jan 2013, 02:06 PM
Raj, have you found a solution? I'm having the same problem.
0
Emil
Top achievements
Rank 2
answered on 22 Jan 2013, 06:06 PM
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
0
Stefan
Telerik team
answered on 25 Jan 2013, 11:35 AM
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.
0
vahid
Top achievements
Rank 1
answered on 03 Jun 2016, 02:31 AM

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

 

0
vahid
Top achievements
Rank 1
answered on 03 Jun 2016, 02:31 AM
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
0
Dimitar
Telerik team
answered on 03 Jun 2016, 11:16 AM
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.
Tags
GridView
Asked by
John Kok
Top achievements
Rank 1
Answers by
Nick
Telerik team
Jonah
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Raj
Top achievements
Rank 1
Julian Benkov
Telerik team
Stefan
Telerik team
Emil
Top achievements
Rank 2
vahid
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or