all groups > dotnet windows forms databinding > november 2007 >
You're in the

dotnet windows forms databinding

group:

Custom TypeConverter, vsFlexGrid, Binding


Custom TypeConverter, vsFlexGrid, Binding Steve D.
11/14/2007 8:57:08 AM
dotnet windows forms databinding:
I wrote a custom type converter class to convert a Single to a string with
knowledge of a "missing" value.



I decorated a property of my business object, of type Single, to use this
custom TypeConverter.



When I bind this property to a text box, (Windows Forms) the type converter
gets used and works as expected.



I have a collection of these business objects. I bind this collection to a
vsFlexGrid from ComponentOne. I connect one of the columns in the grid to
the property which is decorated to use the custom TypeConverter. This column
does bind to the property because it displays the values. However, it never
fires any code in the TypeConverter class and it does not display my
'missing' value as an empty string - which is my intention.



Any clues on this would be helpful. Does vsFlexGrid not support custom type
converters? Since this is a collection do I have to let the collection know
about the custom TypeConverter, if so, how is this done?



Thanks,

Steve



Re: Custom TypeConverter, vsFlexGrid, Binding Marc Gravell
11/14/2007 2:17:18 PM
It sounds like flexgrid is not checking at the PropertyDescriptor
level for a TypeConverter.

The most pragmatic solution might be to simply expose a second
property which acts as a facade, doing the translation for you - not
very pure, but it'll work every time - i.e.

[EditorBrowsable(EditorBrowsableState.Never)] // removes from
intellisense
public string SomePropertyString {
get {return SomeFormatCode(SomeProperty);}
set {SomeProperty = SomeParseCode(value);}
}

Re: Custom TypeConverter, vsFlexGrid, Binding Steve D.
11/14/2007 2:55:17 PM
Thanks Marc,

I have since discovered that the humble DataGridView control does the right
thing and fires the type converter! For now, I will us it instead of
vsFlexGrid.

Steve

[quoted text, click to view]

AddThis Social Bookmark Button