Home Forums WPF controls Xceed DataGrid for WPF deleting issues

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

    I’ve got some strange deleting issues. I’ll post my delete code, then do my best to describe the problems 🙂

    private void HandleDeleteRows(DataGridControl dataGridControl)
    {
    if (dataGridControl.SelectedItems.Count < 1)
    return;

    ItemCollection itemCollection = dataGridControl.Items as ItemCollection;

    if (itemCollection == null)
    return;

    int count = dataGridControl.SelectedItems.Count;

    for (int i = 0; i < count; i++)
    {
    MyObj item = (MyObj)dataGridControl.SelectedItems[0];
    if (item != null)
    {
    MyParent.Lines.Remove(item.LineID);
    }
    }
    dataGridControl.SelectedItems.Clear();
    dataGridControl.UpdateLayout();
    }

    Issues;

    Deleting a single item works fine. The issues arise when trying to delete multiple rows.

    Case A) delete single item == works fine

    Case B) ctrl+click to select multiple contiguous rows (as in a solid block of rows)[1] == works fine

    Case C) ctrl+click to select multiple NON contiguous rows == FAIL. In this case, after the first iteration through the loop the SelectedItems clears.

    Sample;
    Select Rows 1, 2, 3, 6 and 9 == Fail.

    Case D) ctrl+click to select multiple NON contiguous rows and then DESELECT the last row == works fine.

    Sample;
    Select Rows 1, 2, 3, 6, 9 and 11 and then DESELECT 11 == works fine.

    Obviously the deselection of the last row changes something, I just cant work out what. I thought it was related to the location of the ‘black arrow’ (is that for CurrentItem?) but with the contiguous selection the item with the ‘black arrow’ is successfully deleted.

    any insights?

    thanks

    [1] as it is a contiguous selection shift+click also works

    Imported from legacy forums. Posted by Jack (had 4735 views)

    Xceed Support
    Member
    Post count: 5658

    Thank you for reporting this…

    We will update you in this thread when we have more details.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 271 views)

    Xceed Support
    Member
    Post count: 5658

    Can you describe how the deletion “fails”? Is there an exception? Are some items not deleted?

    Imported from legacy forums. Posted by Marcus [Xceed] (had 281 views)

    User (Old forums)
    Member
    Post count: 23064

    Case C) ctrl+click to select multiple NON contiguous rows == FAIL. In this case, after the first iteration through the loop ***the SelectedItems clears***.

    By clears, I mean…well… clears. There are no longer any selected items after the FIRST deletion, even if I had 6 selected.

    Is there a preferred/known way to delete items in the samples? The code I’m using was based on several posts in this forum, plus some mucking about. It would be really helpful if Xceed created a sample of how to delete.

    cheers

    Imported from legacy forums. Posted by Jack (had 616 views)

    User (Old forums)
    Member
    Post count: 23064

    i probably should re-emphasise that when I DESELECT the last row selected and then try to delete, it all works.

    Rows 1, 2, 3, 6, 9 == fails
    Rows 1, 2, 3, 6, 9, 11 then deselect 11 == works (as in 1,2,3,6 and 9 are successfully deleted)

    Imported from legacy forums. Posted by Jack (had 614 views)

    Xceed Support
    Member
    Post count: 5658

    Hi,

    I needed more details just to ensure I was repro-ing the same issues as you encountered…

    Either way, I found a quick workaround that would eliminate the issue (in the mean time we fix this behavior)…

    If you create a copy of the SelectedItems collection, you can use the copy to cycle through the list of SelectedItems…

    object[] selectedItems = new object[ myGrid.SelectedItems.Count];
    myGrid.SelectedItems.CopyTo( selectedItems, 0);

    //loop on selectedItems instead of myGrid.SelectedItems

    Let me know if you encounter any more problems while using this workaround.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 265 views)

    User (Old forums)
    Member
    Post count: 23064

    This issue has been fixed, you can donwload the latest package <a href=”http://xceed.com/pages/TopMenu/Downloads/Trials.aspx”>here </a>

    Imported from legacy forums. Posted by Matt (had 5409 views)

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