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

Problem Changing Sorted Column

7 Answers 137 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 18 Jan 2011, 09:51 PM
Hi All,

I have a RadGridView with only about 40 rows and about 15 columns.  I am sorting by two of these columns, "Presented" and "Number".  At some interval, I loop through the entire grid and set the "Presented" value for each row to 0, which of course will change the sot order of the grid (because I am sorting by "Presented", which I have just changed to 0).  It seems that when this happens, some of the rows never get iterated over because they have been moved in the rows collection - due to sorting.  I have pasted my code below ... should I iterate and change the call values some other way?

I first tried this:
foreach (GridViewRowInfo dr in grdHuntGroups.Rows)
{
    dr.Cells["Presented"].Value = 0;
    dr.Cells["Handled"].Value = 0;
    dr.Cells["Voicemail"].Value = 0;
    dr.Cells["Abandoned"].Value = 0;
    dr.Cells["Overflowed"].Value = 0;
}


And have since tried this:
for (int i = 0; i < grdHuntGroups.Rows.Count; i++)
 {
     grdHuntGroups.Rows[i].Cells["Presented"].Value = 0;
     grdHuntGroups.Rows[i].Cells["Handled"].Value = 0;
     grdHuntGroups.Rows[i].Cells["Voicemail"].Value = 0;
     grdHuntGroups.Rows[i].Cells["Abandoned"].Value = 0;
     grdHuntGroups.Rows[i].Cells["Overflowed"].Value = 0;
}

Thank You!!

7 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 18 Jan 2011, 10:24 PM
Hello,

From what I understand of your scenario, you need to wrap your foreach statement with
this.radGridview1.BeginUpdate();
// do stuff
this.radGridView1.EndUpdate();

or (does the same)
using (this.radGridView1.DeferRefresh())
    // do stuff
}

This will ensure your update is both faster, and that rows are not updated until the operation is complete.
Hope that helps
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 20 Jan 2011, 06:31 PM
Hello,

Did this help? If so please remember to mark as answer. If I've misunderstood or you need more assistance, just let me know.
Thanks
Richard
0
Matt
Top achievements
Rank 1
answered on 20 Jan 2011, 06:58 PM
No, unfortunately it did not help.  I was able to do a workround ... I first removed all sorting, changed the values, then reapplied the sorting (as seen below).  It happens so fast that is is not noticable (again, I only have about 20 rows), but I would still like a way to do this without editing the sorting.  I did try the RadGridView.BeginUpdate() and RadGridView.EndUpdate() without success.

List<GridSortField> mExpressions = new List<GridSortField>();
foreach (GridSortField feExpression in grdHuntGroups.MasterGridViewTemplate.SortExpressions)
    mExpressions.Add(feExpression);
grdHuntGroups.MasterGridViewTemplate.SortExpressions.Clear();
 
foreach (GridViewRowInfo dr in grdHuntGroups.Rows)
{
    dr.Cells["Presented"].Value = 0;
    dr.Cells["Handled"].Value = 0;
    dr.Cells["Voicemail"].Value = 0;
    dr.Cells["Abandoned"].Value = 0;
    dr.Cells["Overflowed"].Value = 0;
}
 
foreach (GridSortField feExpression in mExpressions)
    grdHuntGroups.MasterGridViewTemplate.SortExpressions.Add(feExpression);
0
Matt
Top achievements
Rank 1
answered on 20 Jan 2011, 07:07 PM
And some clarification on my last post, I am using BeginEdit() as opposed to BeginUpdate().  The version I am using does not have a BeginUpdate() method.  I am using 2009.2.9.729.
0
Richard Slade
Top achievements
Rank 2
answered on 20 Jan 2011, 08:40 PM
Hello,

I'd certainly advise upgrading to the latest version if possible, The Q3 2010 SP 1 release has many new controls, enahancements, fixes and performance upgrades that you can take advantage of.
I'm afraid i don't have this older version of the controls to try your solution.
If you need anyhting else howeverm please just ask
Richard
0
Matt
Top achievements
Rank 1
answered on 20 Jan 2011, 08:45 PM
Thanks for the advice and help Richard!
0
Jack
Telerik team
answered on 21 Jan 2011, 10:56 AM
Hi Matt,  our latest release contains many improvements and using the suggested by Richard methods will help in solving the described issue. The Begin/EndUpdate methods are firstly introduced in Q2 2010. In your version you can call the GridElement.BeginUpdate/EndUpdate methods instead:
this.radGridView1.GridElement.BeginUpdate();
//...
this.radGridView1.GridElement.EndUpdate();

I hope this helps. If you need further assistance, please write back.

@Richard, thank you for your suggestion. I updated your points accordingly.

Best wishes,
Jack
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
Tags
GridView
Asked by
Matt
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Matt
Top achievements
Rank 1
Jack
Telerik team
Share this question
or