Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Binding.Format event not firing.

$
0
0

All, I have a C#.Net 4.0 desktop Winforms question. In the past I have used bindings and the Binding.Format event to take int.MinVal default values from custom class members and display them as string.empty. I want to do that here but it seems the Binding.Format event is never called. Here's the code:

//First I nullify the DataSource of my BindingSource.
//The DataSource is a custom class that implements INotifyPropertyChanged.
this._bsOrder.DataSource = null;

//Next I create the Binding.
Binding shipNumberBinding = new Binding("Text", this._bsOrder, "ShipmentNumber", true);

//Then add the event handler.
shipNumberBinding.Format += new ConvertEventHandler(formatShipNumber);

//And lastly set the BindingSource.DataSource so the controls, and their data bindings, will refresh.
this._bsOrder.DataSource = this._adminOrder;

The handler is defined as so:

        private void formatShipNumber(object sender, ConvertEventArgs e) 
        {
            if (e.Value == int.MinValue.ToString()){ e.Value = null; }
        }

... but it never fires. I have tried rearranging the order of how each step is called, but with no luck. I HAVE done this in the past with success, but the only difference I can see is that in the past the Binding was directly bound to the underlying custom class property with a BindingSource in the middle, as I do here. But isn't that the point of the BindingSource?

Thanks.

Kurt


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>