0

I have a custom DataGridView cell I'm using to display the contents of MyType objects. To control how they're being formatted I'm overriding the GetFormattedValue() and FormattedvalueType methods of DataGridViewTextBoxCell because in this case I don't want to use the default ToString() method. The problem is that when I do this the DataGridView is sorting the column by the string in FormattedValue instead of by Value.

I'm not seeing a method I can override to change the sort behavior of the column. While I know I can, I don't want to have to write custom DataGridView.Sort() methods because I'm using MyType columns in multiple DataGridViews.

1 Answer 1

1

Are you filling the DGV manually, or using databinding ?

In the former case, you can handle the SortCompare event, as explained in the link posted by SwDevMan81.

In the latter case, make sure your MyType class implements IComparable. This implementation will be used by the DGV to sort the data.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.