I tried the following code to format a databound control with custom formatting. When you step through the code, the Format method is never called for the custom formatter, it always defaults to the global Format function. This to me seems like a pretty major bug in Microsoft's databinding implementation. Anyone else notice this? Here is the sample code:
Below is the form binding data to a label to use a custom formatter:
namespace
BindingFail{
public partial class Form1 : Form{
public Form1(){
InitializeComponent();// binding a custom formatter to
Binding b = label2.DataBindings.Add("Text", numericUpDown1, "Value", true, DataSourceUpdateMode.OnPropertyChanged, "<not specified>", "{0}.555", new MyCustomFormatterNamespace.CustomFormatter());
// use this to fix the problem
//b.Format += new ConvertEventHandler( new
// MyCustomFormatterNamespace.CustomFormatter());
}
private void Form1_Load(object sender, EventArgs e)

Join the conversation! Your thoughts help the community grow.