Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance DataGridView to support non-destructive (multi column) Sort #5202

Open
coderb opened this issue Jul 2, 2021 · 8 comments
Open

Enhance DataGridView to support non-destructive (multi column) Sort #5202

coderb opened this issue Jul 2, 2021 · 8 comments
Assignees
Labels
api-suggestion (1) Early API idea and discussion, it is NOT ready for implementation area-controls-DataGridView help wanted Good issue for external contributors
Milestone

Comments

@coderb
Copy link

coderb commented Jul 2, 2021

DataGridView.Sort seems to be implemented via the quick sort algo in DataGridViewRowCollection.RowArrayList.

I would like to be able to sort the DataGridView in a non-destructive (stable) way when changing the sort column (clicking the header to sort). Eg. If I sort on the first column and then sort on the second, the rows remain sorted by column 1 for equal values of column 2.

@krwq
Copy link
Member

krwq commented Jul 6, 2021

@RussKie RussKie transferred this issue from dotnet/core Jul 6, 2021
@RussKie RussKie added the help wanted Good issue for external contributors label Jul 6, 2021
@RussKie RussKie added this to the Future milestone Jul 6, 2021
@coderb
Copy link
Author

coderb commented Jul 6, 2021

@krwq nope, that link is a no go. i need to be able to (continue to) use the column headers to do the sorting. i've tried everything i could find on the web/stack overflow and even tried doing some reflection to SortInternal when overriding the Sort() method of DataGridView but it doesn't like to be passed both a column and comparer object.

it seems like some code support in DataGridView is appropriate.

@merriemcgaw merriemcgaw added the api-suggestion (1) Early API idea and discussion, it is NOT ready for implementation label Jul 7, 2021
@coderb
Copy link
Author

coderb commented Apr 4, 2022

i've requested that the dotnet core project add a stable sort algorithm.
dotnet/runtime#67546

@jkotas
Copy link
Member

jkotas commented Apr 9, 2022

@corerb DataGridViewRowCollection.RowArrayList has its own custom sort implementation:

// Custom recursive QuickSort needed because of the notion of shared rows.
. Unless the implementation is refactored to use the sort implementation from the core libraries, you would not be able to use stable sort even if it was added to the core libraries.

Also, it should be fairly straightforward to modify the compare function to take the current order into account. It may take a bit extra memory (e.g. temporary array of integers). It is negliable given how much memory is occupied by each row.

@RussKie RussKie added help wanted Good issue for external contributors and removed help wanted Good issue for external contributors labels May 2, 2022
@ghost ghost modified the milestones: Future, Up-for-grabs May 5, 2022
@ghost
Copy link

ghost commented May 5, 2022

This issue is now marked as "up for grabs", and we’re looking for a community volunteer to work on this issue. If we receive no interest in 120 days, we will close the issue. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@JeremyKuhne
Copy link
Member

@KlausLoeffelmann this sounds like a useful feature, thoughts?

@KlausLoeffelmann
Copy link
Member

Hmm. I am a bit torn, also since Data Binding might be an issue here, since - if I remember correctly - sorting will then be delegated to a BindingList<T> and not be done by the DataGridView? But - I would need to refresh my memory what exactly is happening.

For unbound data sources, I would think implementing a MultiColumnSorter (based on IComparer) to pass to a DataGridView's Sort method should work already.

So, I don't know. Am I missing something else which should justify this feature?

@KlausLoeffelmann KlausLoeffelmann modified the milestones: .NET 9.0, Future Jul 23, 2024
@KlausLoeffelmann
Copy link
Member

I am moving this to future. We won't have the bandwidth in the nearer future to address this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion (1) Early API idea and discussion, it is NOT ready for implementation area-controls-DataGridView help wanted Good issue for external contributors
Projects
None yet
Development

No branches or pull requests

7 participants