Home Forums WinForms controls Xceed Grid for WinForms Forced Row Change in Databound grid

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #13812 |

    I upgraded a little while ago to the 2.3 grid (bit slow to change I know but there was no compelling reason to move up).

    I encountered a problem with my app where the current/selected row resets (I think on every data changed event) to be the top most row.

    This for obvious reasons renders the grid useless. I upgraded to 2.2.5362.0 but the problem still exists (but now it does it even faster)

    Any ideas what is broken and if there are work arounds?

    Matt

    Imported from legacy forums. Posted by shuggycouk (had 3461 views)

    User (Old forums)
    Member
    Post count: 23064

    Reply To Self:
    This is due to the EndInit method on DetailGrid (used even if the grid is not using Master/Detail triggering a resort on the data rows which in turn triggers a method which explicitly does this reset!

    found

    in the changes from 2.0.102 and 2.1

    “When code executes between GridControl.BeginInit / EndInit, it will keep the new and modified DataRows or Groups from sorting. When EndInit is called, it will trigger a global resorting”

    No idea why this change doesn’t

    1) have a simple means of disabling said behaviour
    2) at least only trigger if a sort has been activated!

    It is trivial to achieve this in a test app. just:
    a) add a default setup grid to a form.
    b) set the DataSource to some IBindingList implementation.
    c) add some elements to the IBindingList
    d) add a button whose event handler:
    d1) calls begin init
    d2) alters the state of an element
    d3) calls end init

    run app, select some row not at the top, hit the button. Hey presto selection goes.

    Does no-one else care about this?

    [sigh] have raised a support request, hopefully will at least have a workaround, if not it’s adios Xceed.Grid.

    Matt

    Imported from legacy forums. Posted by shuggycouk (had 453 views)

    User (Old forums)
    Member
    Post count: 23064

    What you could do (and what I do): store the current row index in a variable before calling BeginInit, and set the current row back after calling EndInit.
    Here’s some code I use:<code>int rowIndex = -1, columnIndex = -1;
    private void SaveCursorPosition() {
    if (grid.DataRows.Count == 0)
    rowIndex = -1;
    else {
    Xceed.Grid.DataRow row = grid.CurrentRow as Xceed.Grid.DataRow;
    if (row != null) rowIndex = grid.GetSortedDataRows(true).IndexOf(row);
    else rowIndex = -1;
    }
    if (grid.CurrentColumn != null)
    columnIndex = grid.Columns.IndexOf(grid.CurrentColumn);
    else columnIndex = -1;
    }
    private void LoadCursorPosition() {
    if (rowIndex >= 0 && rowIndex < grid.GetSortedDataRows(true).Count) {
    Xceed.Grid.DataRow row = grid.GetSortedDataRows(true)[rowIndex];
    if (row.CanBeCurrent && row.Visible) {
    row.BringIntoView();
    grid.CurrentRow = row;
    if (row.CanBeSelected) {
    grid.SelectedRows.Clear();
    grid.SelectedRows.Add(row);
    }
    }
    }
    if (columnIndex >= 0 && columnIndex < grid.Columns.Count)
    grid.CurrentColumn = grid.Columns[columnIndex];
    }</code>

    Imported from legacy forums. Posted by Tommy (had 374 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for the sample – I may throw that in (I have just disabled the init at the moment and hoped that performance won’t nail me 🙂

    Apparently it should only happen if the column involved is sorted but it is broken. Hopefully the bug fix will not be too tricky [laughs at his own little joke there :)]

    To be honest though if it still does it when sorted then I will have to implement this anyway (since the user selection of row allows them to do various things based on said selection)

    be nice to have a bool property SelectionFollowsTopRowWhenSorted (or something a little less wordy perhaps)

    Thanks again,
    Matt

    Imported from legacy forums. Posted by shuggycouk (had 317 views)

    User (Old forums)
    Member
    Post count: 23064

    The code uses <b>grid.GetSortedDataRows()</b> instead of <b>grid.DataRows</b>, so sorting should be covered. I’ve been using this code (not exactly the same, but close enough) for almost 2 years now.

    Imported from legacy forums. Posted by Tommy (had 4948 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.