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

formating a textbox before binding

$
0
0

I have three textbox's the first contains a $$ and does not get bound until the third textbox is completed, I would like to format the first box when it has lost the focus, as well as when displaying the record - can anyone suggest the best method to use.. (lost focus does not seem to work).

   //Formatted fields
                this.txtNetAmount.DataBindings.Clear();
                Binding b4 = new Binding("Text", this.bsHeader, "APINHAMOUNTNET", true);
                b4.Format += new ConvertEventHandler(this.hnDisplayAmount);
                this.txtNetAmount.DataBindings.Add(b4);
--------------------------------------------------------------------------------------------------------------

    private void hnDisplayAmount(object sender, ConvertEventArgs cevent)
        {
            // The method converts only to string type. Test this using the DesiredType.
            if (cevent.DesiredType != typeof(string )) return;
            {
                try
                {
                   // cevent.Value = ((double)cevent.Value).ToString("{0:0.00}");
                    cevent.Value = string.Format("{0:0.00}", cevent.Value);
                }
                catch { } //do nothing
            }
        }//----------------------------------------------------------------------------------


Viewing all articles
Browse latest Browse all 2535

Trending Articles



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