Custom DataGridView column sort based on Value not Formatted value

Posted by Dan Neely on Stack Overflow See other posts from Stack Overflow or by Dan Neely
Published on 2010-05-21T20:01:45Z Indexed on 2010/05/21 20:30 UTC
Read the original article Hit count: 257

Filed under:
|
|
|
|

I have a custom DGV 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 DGV 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 Sort mthods for the DGVs themselves because I'm using this in multiple DGV's.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET