Skip to content

Fix brief deselection of selected item to be selected when changing selected item. - #379

Merged
punker76 merged 1 commit into
punker76:developfrom
Metritutus:BriefDeselectionOfSelectedRowFix
Aug 11, 2021
Merged

punker76 merged 1 commit into
punker76:developfrom
Metritutus:BriefDeselectionOfSelectedRowFix

Conversation

@Metritutus

Copy link
Copy Markdown
Contributor

In the SetSelectedItem() method of ItemsControlExtensions, it sets the SelectedItem to null before setting it to the value passed in. For an existing multi-selection, the value being selected could already be within that existing selection, meaning that the item we wish to select is being deselected and then selected again.

This behaviour can make SelectionChanged event handling somewhat problematic further down the line (an application I'm working manages what selection behaviour in the SelectionChanged events for nested DataGrid instances, and the deselection of all rows, followed by the selection of the correct one for the parent DataGridhad implications for the childDataGrid` instance's selected rows. This relates to the other pull request I've raised, #378).

What changed?

  • Updated SetSelectedItem() method in ItemsControlExtensions to not deselect the item we're selecting before before selecting it again.

The original change (df10543) to set the SelectedItem to null first before setting it to the new value was made to resolve issue #21. The change made in this pull request does not regress that issue.

* Updated SetSelectedItem() method in ItemsControlExtensions to not deselect the item we're selecting before before selecting it again.
@Metritutus Metritutus changed the title Update ItemsControlExtensions.cs Fix brief deselection of selected item to be selected when changing selected item. Aug 8, 2021
@Metritutus

Copy link
Copy Markdown
Contributor Author

Although I myself am working with DataGrid controls (which extends MultiSelector), I've made this change to the ListBox part of the code as well as it appears to behave in the same way. However, as my work has primarily been with DataGrid controls, it means that I haven't tested the ListBox changes as thoroughly as the MultiSelector ones, although it seems to be fine, but if you want me to revert that change I can do so.

Also, I've not updated the Selector part of the code (yet) because, from looking at it, I'm not certain that the selector.SetCurrentValue(Selector.SelectedItemProperty, null); line is actually needed at all.

The original issue (#21) would only have occurred for scenarios where multiple items are selected. Selector doesn't provide public APIs to allow for the selection of multiple items.

I therefore suspect that that line could probably be outright removed, and will update this pull request with that change if a maintainer agrees.

@punker76 punker76 added this to the 2.4.0 milestone Aug 11, 2021
@punker76
punker76 merged commit a08272a into punker76:develop Aug 11, 2021
@punker76

Copy link
Copy Markdown
Owner

@Metritutus your changes have been merged, thanks for your contribution 👍

@Metritutus

Copy link
Copy Markdown
Contributor Author

@punker76 Did you have any comment regarding this?

@punker76

Copy link
Copy Markdown
Owner

@Metritutus Yes, I think we don't need that, so I commented this out.

@Metritutus

Copy link
Copy Markdown
Contributor Author

@punker76 Ah sorry, I missed that you'd made alterations after the merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants