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

Sorting. Need advice.

7 Answers 103 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jose Mejia
Top achievements
Rank 1
Jose Mejia asked on 18 Mar 2011, 12:35 PM
Hello.

I have following situation: I have two grids and I need to some synchronize rows between them.
Synchronization implemented by sorting rows by some field, say syncId: if two rows must be synchronized
then I find the  highest syncId, increase it and assign to them. So the new synchronized rows is moved to
the top of grid. When I  add new rows (AddNewRowPosition = Bottom) there are blinking because it first tries to sort  new added row.
And also there is problem when removing rows when sorting is enabled - it select not the next row before deleted, but jumps higher,
beacuse added rows have the same syncId, say  -1, and when I delete one of the rows it jumps to the first row with syncId = -1. Not very good for usability. So is there any mechanism to suppress sorting while adding and removing rows.

Any thoughts?

7 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 19 Mar 2011, 10:47 AM
Hello Jose,

Could you please post some sample code, it will be easier to find a solution that suits your needs using a sample.

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Jose Mejia
Top achievements
Rank 1
answered on 21 Mar 2011, 09:54 AM
Hello, Emanuel!

Simply speaking, I need possibility to turn off grid sorting while adding and removing rows and then turn on again.
Is it possible?
0
Emanuel Varga
Top achievements
Rank 1
answered on 21 Mar 2011, 10:02 AM
Hello Jose,

Please try just storing the currently selected sort descriptors, clearing the sort descriptors, performing your required actions and reading the previous sort descriptors.

var sortDescriptors = radGridView1.SortDescriptors.ToArray();
radGridView1.SortDescriptors.Clear();
// do something here
radGridView1.SortDescriptors.AddRange(sortDescriptors);

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

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Jose Mejia
Top achievements
Rank 1
answered on 21 Mar 2011, 01:40 PM
Hello, Emanuel!

I already tried this case and for now I'm using it, but it seems to me that from performance point of view
this solution is not ideal,beacuse every time I'm adding sorting descriptors grid begins resorting (I didn't profile application ). What I want, if it is possible, is to freeze grid sorting, add/delete row, and turn sorting on again. Without resorting whole grid. I can gurantee that sorting won't be broken.
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 21 Mar 2011, 04:12 PM
Hello again Jose,

It won't work like that, you could try wrapping your update code in:
radGridView1.BeginUpdate();
// do stuff here
radGridView1.EndUpdate();
 
//or
 
using (radGridView1.DeferRefresh())
{
// do stuff here
}

but it will still cause the grid to update all it's data.

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

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Jose Mejia
Top achievements
Rank 1
answered on 21 Mar 2011, 05:02 PM
Hello, Emanuel!

Thank you very much for your help!

It is pity that there is no functionality to temporarily suppress grid sorting.
0
Julian Benkov
Telerik team
answered on 23 Mar 2011, 01:57 PM
Hi Jose,

You can try also to set EnableSorting property to true/false in you application. Thank you Emanuel for all your comments and suggestions.

Kind regards,
Julian Benkov
the Telerik team
Tags
GridView
Asked by
Jose Mejia
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Jose Mejia
Top achievements
Rank 1
Julian Benkov
Telerik team
Share this question
or