Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hey all,

 

I've been lurking for awhile and have learned a lot from just reading the posts here.

 

Now I have a question that I can't find the answer to. I hope I'm posting in the right forum. If not, I apologize.

 

I have several text boxes on a form that are binded to fields in an access database. I can't get the fields that are formatted as currency in Access to display as currency in the text box. :confused:

 

I've tried using FormatCurrency() around the binding for the text box but I get an error.

 

Since all the data binding is done in the property setting for the text box, the load event passing the database to the binding is the only code I really have to show:

 

Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
       daStocks.Fill(DsStocks1)
       currManager = Me.BindingContext(DsStocks1, "Stocks")
End Sub

 

I'm sure the answer is right under my nose.

 

Any help would be appreciated.

 

Thanks!!

 

Heather

Posted
I haven't used the BindingContext as yet, I assign the dataset fields to the textboxes using my own code. I therefore use the format() method to display the currency symbol.
My website
Posted

After I let it sit for awhile, I was able to come back and figure out how I could solve my problem.

 

Here's the code I ended up using to pass the values to a variable then format the variable to be passed back to the text box as currency. Works like a charm.

 

Private Sub curformat()
       Dim pprice As Decimal
       Dim scommission As Decimal
       Dim sprice As Decimal
       Dim pcommission As Decimal
       Dim gainloss As Decimal
     
      'store value from text boxes in a variable
       pprice = txtPurPrice.Text
       scommission = txtSalesCommission.Text
       sprice = txtSale.Text
       pcommission = txtPurCommission.Text
       gainloss = lblCapGL.Text
       
      'pass formatted value back to text box to display as currency
       txtPurPrice.Text = FormatCurrency(pprice)
       txtSalesCommission.Text = FormatCurrency(scommission)
       txtPurCommission.Text = FormatCurrency(pcommission)
       txtSale.Text = FormatCurrency(sprice)
       lblCapGL.Text = FormatCurrency(gainloss)
   End Sub

 

:D

  • *Experts*
Posted

You can use the Format and Parse events of your DataBindings collection to automatically format data.

 

Here's a code snippet to setup the binding. Check the help on how to code the Format and Parse events - they contain sample code to convert numbers back and forth so that you can type "1,234,999" and it will convert it to "1234999" so that the database won't cause problems.

 

textBox1.DataBindings(0).Parse += new ConvertEventHandler(CurrencyStringToDecimal_Nullable);

 

That's C# syntax. For VB, I think you'll want to use AddHandler but I don't know the syntax. Check the help for the Format or Parse event and all will be revealed :)

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...