I'm monkeying around with databinding, trying to learn all the ins and outs. I'm populating a label from one of my business objects properties which is a string, however, I want some formatting done on the string first. I got this working using the binding's Format event. But, I want to go one step further. Instead of using the Format event, I'm trying to set the FormatString and FormatInfo properties to make the databinding go through the formatter I wrote. The problem is, it's not. It's just assigning the string straight from the BO to the label. Can anyone spot what step I'm missing here?
- Binding taxBinding = new Binding("Text", mCustomer, "TaxNumber");
-
taxBinding.FormattingEnabled = true;
-
if (mCustomer.TaxNumberIsSSN)
-
taxBinding.FormatString = TaxNumberFormatter.SSN_FORMAT;
-
else
-
taxBinding.FormatString = TaxNumberFormatter.TAX_ID_FORMAT;
-
taxBinding.FormatInfo = new TaxNumberFormatter();
-
taxBinding.NullValue = string.Empty;
-
lblTaxNumber.DataBindings.Add(taxBinding);
-
//taxBinding.Format += new ConvertEventHandler(TaxNumberFormatter.TaxBinding_Format);
-
TaxNumberFormatter implements both IFormatProvider and ICustomFormatter, however, none of the contracted methods are ever called when I put breakpoints on them and this is evident in that my string isn't formatted on the label. This seems so simple yet I can't find what step I'm missing from any online document or my databinding book. Can anyone shed some light on this? If I uncomment the commented line it works fine without all the extra stuff above it, but as I said I'm trying to get a grasp on automatic formatting. Is this normal behavior since no actual conversion needs to take place from my BO.TaxNumber property to the label.Text property? Am I forced to use the Format event because no conversion is taking place?
If you guys need any extra information let me know. I've refrained from showing the TaxNumberFormatter code in it's full text but can if necessary.
Thanks!
ope