Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
610
Programmatically select rows when new row is selected
posted

The basic functionality I'm looking for is the ability to select rows together. If I have some ID with duplicates, and I want to select all other rows with the same ID together, how can I do that?

My current attempt involves handling the AfterRowActivate event, I then loop through (I realize this is a bad idea, and I'm going to try to replace it with a dictionary to get O(1) lookup time) and find all the rows that match.

I've tried toggling Row.Selected and/or adding those rows to the UltraGrid.Selected.Rows collection, but as soon as those rows are selected, they are deselected again (you can visually see this happen).

CellClickAction is set to RowSelect.

I've attached a sample project, try selecting one of rows with "Bob" for first name. For me, this causes the other row with "Bob" to get selected momentarily, then immediately deselect. Perhaps I'm handling the wrong event? Thanks y'all!

Edit: Since rows selected together should probably also be deselcted together, should I really be handling the AfterSelectChange event?

SelectRowsTogether.zip
Parents
  • 610
    Verified Answer
    Offline posted

    Handling the AfterSelectChange event was the right way to go.

    Attached is the code that works for me. Note that the logic in the event handler is O(n^2), so if you have lots of rows, that is a terrible way to do it. Replacing the inner loop with a dictionary would be one way to handle that.

     

    SelectRowsTogether-ItWorksYay.zip
Reply Children
No Data