I am trying to use IFormatProvider to configure some data bindings; however, the IFormatProvider class is never called. I set breakpoints at the beginning of both functions in my personalization class, and none of them fell into data binding. When I use my own formation class with String.Format, it works.
I am using .Net 2.0 and winforms.
This is how I do 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 own formation 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;
}
}
source
share