Current filter:
                                You should refresh the page.
                                  • I encounter a problem:

                                    I have tow grids on the form. I write code like this

                                    for(int i = 0; i< view.RowCount; i++)
                                    {
                                    int rowhandle = gridView.GetRowHandle(i);
                                    SomeClass sc = gridView.GetRow(rowhandle) as SomeClass;

                                    ....
                                    }

                                    I found that after sorting, some row handles getting from GetRowHandle(i) are invlid.

                                    But, in another grid, it is ok.

                                    What's the problem?

                                • Maike Liu 03.13.2013

                                  If I don't sort,

                                  the following two codes are the same.

                                  A
                                  for(int i = 0; i< view.RowCount; i++)
                                   {
                                   int rowhandle = gridView.GetRowHandle(i);
                                   SomeClass sc = gridView.GetRow(rowhandle) as SomeClass;
                                   
                                  ....
                                   }
                                   

                                  B
                                  for(int i = 0; i< view.RowCount; i++)
                                   {
                                    SomeClass sc = gridView.GetRow(i) as SomeClass;
                                   
                                  ....
                                   }

                                1 Solution

                                Creation Date Importance Sort by

                                If you wish to traverse through all data rows in grid, I suggest you use the following code:

                                [C#]
                                for(int i = 0; i< view.DataRowCount; i++) { SomeClass sc = gridView.GetRow(i) as SomeClass; .... }
                                See Also:
                                Traversing Rows

                                UPDATED 3/14/2013:

                                GridControl starts sorting records after one of them was modified, which updates the row position. To prevent this behavior, set the ColumnViewOptionsBehavior.ImmediateUpdateRowPosition property to false.

                                Note that after changing the ImmediateUpdateRowPosition property to false, modified records will keep their positions until the View is manually refreshed. To manually refresh the View, call the BaseView.RefreshData method.

                                Alternatively, you can prevent updating the View if you enclose your code within the ColumnView.BeginDataUpdate and BaseView.EndDataUpdate methods.

                                I hope that this information will help you. If not, please do not hesitate to reactivate this ticket.

                                • Maike Liu 03.13.2013

                                  I want to traverse through all data, and set value for certain rows AFTER SORTING.

                                  for(int i = 0; i< view.DataRowCount; i++)
                                  {
                                  SomeClass sc = gridView.GetRow(i) as SomeClass;
                                  ....
                                  //later, I do
                                  gridView.SetRowCellValue(i, ....)
                                  }

                                  I found that if I use "i", it set to other place after sorting. So I change to code A. then I found it worked for some grids, and not work for some grids. Is there any setting affect this?

                                • Alisher (DevExpress Support) 03.14.2013

                                  Hi Mike,

                                  I have updated the original answer. Please check it.

                                • Maike Liu 03.15.2013

                                  I do have that "BeginUpdate"-"EndUpdate" pair.

                                  The strange thing is when I call GetRowHandle(i), it returns an invlid rowhandle.

                                • Alisher (DevExpress Support) 03.17.2013

                                  Hi Mike,

                                  As I understand, you are trying to use the GridControl.BeginUpdate and GridControl.EndUpdate methods to prevent grid updates caused by data-aware operations (adding, deleting records, sorting and grouping data).

                                  According to our documentation:
                                  The BeginUpdate and EndUpdate methods do not prevent grid updates caused by data-aware operations. To prevent the grid from being updated in these instances, call the BaseView.BeginDataUpdate and BaseView.EndDataUpdate methods.

                                  For more information regarding this, please check the BaseView.BeginDataUpdate and BaseView.EndDataUpdate articles. We are looking forward to your results.