ParentRowIndex vs SortRows

  • Rating
    babe59 4 months, 1 week ago

    Hello,

    FarPoint.Win.Spread, Version=8.35.20151.0

    I use a hierarchical grid. After loading data, I use

    grdErrorMessage.Sheets[0].SortRows(1, true, false)

    to sort row.
    After that the parentRowIndex is not good.
    It’s the same if I sort row by clicking on column header

    ex :
    Befort Sort
    Row C
    Row C.1 (parentRowIndex = 0)
    Row C.2 (parentRowIndex = 0)
    RowA
    Row A.1(parentRowIndex = 1)
    Row A.2 (parentRowIndex = 1)
    RowB
    Row B.1 (parentRowIndex = 2)
    Row B.2 (parentRowIndex = 2)

    After Sort
    RowA
    Row A.1(parentRowIndex = 1)
    Row A.2 (parentRowIndex = 1)
    RowB
    Row B.1 (parentRowIndex = 2)
    Row B.2 (parentRowIndex = 2)
    Row C
    Row C.1 (parentRowIndex = 0)
    Row C.2 (parentRowIndex = 0)

    I do that because I search wich row are selected (on a child or on a main) and if row selected on a child, I would like to know parent row index…

    here my code

    SpreadView spreadView = grid.GetRootWorkbook().GetActiveWorkbook();
    SheetView sheet = spreadView.GetSheetView();
    parentRowIndex = sheet.ParentRowIndex;
    
    CellRange[] cellRanges = grid.ActiveSheet.GetChildView(parentRowIndex, 0).GetSelections();

    Then if I select RowC.1 (after sort)
    cellRanges is anpty and parentRowIndex is set to 0

    thks

  • 15p
    Rating
    Kevin Ashley15p 4 months, 1 week ago

    Hello,

    Would it be possible to please provide a small sample application that shows the issue so I can investigate it further?

    Regards,
    Kevin

  • Rating
    babe59 4 months ago

    Hello
    Here a sample project in attached file

    1° click on “Load” button
    2° expand all line
    3° Click on parent line number 3 (message at the bottom “Parent : Ligne : 2″) => OK
    4° Click on on first line of the child view of line number 3 (pk=7) (message at the bottom “Child : parentRowIndex =2 Ligne :0″) => Ok
    5° Click on “Sort Desc” button
    line 3 goes to line 1
    6° Click on on first line of the child view of line number 1 (pk=7) (message at the bottom “Child : parentRowIndex =2 Pa de ligne) => No Ok

    the parent rowIndex stay at value 2 while it is now in first position (index = 0)

    Attachments:
    You must be logged in to view attched files.
  • 50p
    Rating
    Deepak Sharma50p 4 months ago

    Hello,

    Spread for Windows Forms has different model for view and for data. When sorting is applied the ViewModel is changed from Data model.
    You can get the correct parent row after Sorting using “GetViewRowFromModelRow()” method. I changed the follwing line of codes in your sample and it seems to be working fine:

    int i;
                i = fpSpread1.ActiveSheet.GetViewRowFromModelRow(parentRowIndex);
                cellRanges = fpSpread1.ActiveSheet.GetChildView(parentRowIndex, 0).GetSelections();
    
                if (cellRanges.Length > 0)
                    label1.Text = “Child : parentRowIndex = ” + i + ” Ligne :” + cellRanges[0].Row;
    
                else
                    label1.Text = “Child : parentRowIndex = ” + i + ” Pas de ligne”;

    Regards,
    Deepak Sharma

  • Rating
    babe59 4 months ago

    Ok. it’s work.
    I’ve just change “parentRowIndex” by “i” in

    cellRanges = fpSpread1.ActiveSheet.GetChildView(parentRowIndex, 0).GetSelections();

    thanks a lot
    DT

  • 50p
    Rating
    Deepak Sharma50p 4 months ago

    Happy to know that it worked for you!

    Regards,
    Deepak Sharma

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘ParentRowIndex vs SortRows’ is closed to new replies.