views:

90

answers:

2

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.

+1  A: 

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.

Thomas Levesque