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

Manually Re-Sort grid

1 Answer 103 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 17 May 2011, 05:26 PM
Hi All,

I have a Grid bound to a Dictionary<> in C# (Actually bound to Dictionary.Values).  I am doing this because I am editing the values of the grid pretty often and have a large data set, so using the dictionary allows me to find the exact element I am trying to change without looping through the entire collection. 

This is working pretty well.  I realize that a Dictionary doesn't provide notification when the collection is changed, so to show changes in the Grid I call the following 2 lines of code when I change any Dictionary element:
grid.TableElement.Update(GridUINotifyAction.DataChanged);
grid.TableElement.Update(GridUINotifyAction.StateChanged);

This shows all updates!  Horray!  However, it does not resort the grid correctly.  So, if one of the fields that is being sorted changes, the rows do not move accordingly.  I was hoping that I could determine when I might need to resort and call a "Resort()" type method, but it seems like I can't.

How can I get the Grid to resort in this scenario?

Thanks All!

1 Answer, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 20 May 2011, 09:09 AM
Hello Matt,

First thing, can you please tell me why do you need a dictionary to achieve this? (if you may, some very small example when and why would this be useful, because it seems to me that it's more of a pain than gain).

To achieve a full update on the grid, i would suggest wrapping your update code in
radGridView1.BeginUpdate();
// do update stuff here
radGridView1.EndUpdate();
 
// or the nice clean version
using (radGridView1.DeferRefresh())
{
     // do update stuff here
}

This way everything should work fine.

If you have any more questions please just let me know, and if the question has been solved, please mark the all of the helpfull posts as answers, so that others can find the answers to their questions faster.

Best Regards,
Emanuel Varga

Telerik WinForms MVP
Tags
GridView
Asked by
Matt
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Share this question
or