I am trying to use an IFormatProvider to customize some databindings; however the IFormatProvider class is never being called. I put breakpoints at the begining of both functions in my custom formating class and neither are being hit through databinding. When I use my custom formating class with String.Format it works.
I am using .Net 2.0 and winforms.
This is how I do the data bindings:
label1.DataBindings.Add("Text", textBox1, "Text", true,
DataSourceUpdateMode.OnPropertyChanged,
"<NULL>","{0:H}",new MyFormat());
This is how I used String.Format:
string test =(string.Format(_superFormat, "{0}", "this is my arg"));
And this is my custom formating class:
class MyFormat : IFormatProvider, ICustomFormatter
{
string ICustomFormatter.Format(string format, object arg, IFormatProvider formatProvider)
{
string result = ((string)arg).ToUpper();
return result ;
}
object IFormatProvider.GetFormat(Type formatType)
{
if (formatType == typeof(ICustomFormatter))
return this;
else
return null;
}
}