Binding, Format, Parse...Not able to edit

S

Slonocode

I have some textboxes bound to an access db. I wanted to format the
textboxes that displayed currency and date info so I did the following:

Dim WithEvents oBidAmt As Binding
oBidAmt = New Binding("Text", Me.Ds1, "Items.BidAmt")
txtBidAmt.DataBindings.Add(oBidAmt)


Private Sub oBidAmt_Format(ByVal sender As Object, ByVal e As
System.Windows.Forms.ConvertEventArgs) Handles oBidAmt.Format
e.Value = Format(e.Value, "c")
End Sub

Private Sub oBidAmt_Parse(ByVal sender As Object, ByVal e As
System.Windows.Forms.ConvertEventArgs) Handles oBidAmt.Parse
e.Value = Format(e.Value, "D")
End Sub



I am unable to edit the textboxes that are currency formatted. I am able to
edit the textboxes that are date formatted.
When I type a new amount into a textbox with currency formatting it reverts
back to the old amount as soon as I leave the textbox.
The date types do however work as expected.

Any ideas?
Slonocode
 
S

Steven Stein [MSFT]

Slonocode -

The databound textbox is actually throwing an error that you can't catch.
You need to revert the currency back into a format that the db can handle.
(usually accomplished by removing the dollar sign ($, for example))


hope that helps

Steve Stein
VB Team

This posting is provided "AS IS" with no warranties and confers no rights.



--------------------
| From: "Slonocode" <[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.vb
| Subject: Binding, Format, Parse...Not able to edit
| Date: Fri, 16 Jan 2004 19:05:21 -0500
| Lines: 30
| Message-ID: <[email protected]>
| NNTP-Posting-Host: pcp05008461pcs.sanarb01.mi.comcast.net (68.40.85.170)
| X-Trace: news.uni-berlin.de 1074297930 16380971 68.40.85.170 ([137764])
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2720.3000
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2727.1300
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA06.phx.gbl!TK2MSFTNGXA0
5.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!newsfeed01.sul.t-o
nline.de!t-online.de!fu-berlin.de!uni-berlin.de!pcp05008461pcs.sanarb01.mi.c
omcast.NET!not-for-mail
| Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.languages.vb:173793
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| I have some textboxes bound to an access db. I wanted to format the
| textboxes that displayed currency and date info so I did the following:
|
| Dim WithEvents oBidAmt As Binding
| oBidAmt = New Binding("Text", Me.Ds1, "Items.BidAmt")
| txtBidAmt.DataBindings.Add(oBidAmt)
|
|
| Private Sub oBidAmt_Format(ByVal sender As Object, ByVal e As
| System.Windows.Forms.ConvertEventArgs) Handles oBidAmt.Format
| e.Value = Format(e.Value, "c")
| End Sub
|
| Private Sub oBidAmt_Parse(ByVal sender As Object, ByVal e As
| System.Windows.Forms.ConvertEventArgs) Handles oBidAmt.Parse
| e.Value = Format(e.Value, "D")
| End Sub
|
|
|
| I am unable to edit the textboxes that are currency formatted. I am able
to
| edit the textboxes that are date formatted.
| When I type a new amount into a textbox with currency formatting it
reverts
| back to the old amount as soon as I leave the textbox.
| The date types do however work as expected.
|
| Any ideas?
| Slonocode
|
|
|
 
S

Slonocode

"Steven Stein [MSFT]" said:
Slonocode -

The databound textbox is actually throwing an error that you can't catch.
You need to revert the currency back into a format that the db can handle.
(usually accomplished by removing the dollar sign ($, for example))


hope that helps

Steve Stein
VB Team

This posting is provided "AS IS" with no warranties and confers no rights.

I thought I was converting back to decimal with the Parse event. Am I using
the Parse/Format correctly? Do I have to manually remove the "$"?


Private Sub oBidAmt_Format(ByVal sender As Object, ByVal e As
System.Windows.Forms.ConvertEventArgs) Handles oBidAmt.Format
e.Value = Format(e.Value, "c")
End Sub

Private Sub oBidAmt_Parse(ByVal sender As Object, ByVal e As
System.Windows.Forms.ConvertEventArgs) Handles oBidAmt.Parse
e.Value = Format(e.Value, "D")
End Sub
 
S

Steven Stein [MSFT]

Slonocode

You are correct. You need to convert back to decimal from the currency
string in the parse event. Here's a code snippet from the Binding.Parse
topic

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwindowsformsbi
ndingclassparsetopic.asp


Private Sub CurrencyStringToDecimal(sender As Object, cevent As
ConvertEventArgs)
' The method converts back to decimal type only.
If Not cevent.DesiredType Is GetType(Decimal) Then
Exit Sub
End If

' Convert the string back to decimal using the shared Parse method.
cevent.Value = Decimal.Parse(cevent.Value.ToString, _
NumberStyles.Currency, nothing)

End Sub


hope that helps

Steve Stein
VB Team

This posting is provided "AS IS" with no warranties and confers no rights.



--------------------
From: "Slonocode" <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
Subject: Re: Binding, Format, Parse...Not able to edit
Date: Tue, 20 Jan 2004 20:41:20 -0500
Lines: 32
Message-ID: <[email protected]>
References: <[email protected]>
NNTP-Posting-Host: pcp05008461pcs.sanarb01.mi.comcast.net (68.40.85.170)
X-Trace: news.uni-berlin.de 1074649287 19687756 68.40.85.170 ([137764])
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2720.3000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2727.1300
Path: cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.su
l.t-online.de!newsfeed01.sul.t-online.de!t-online.de!fu-berlin.de!uni-berlin
.de!pcp05008461pcs.sanarb01.mi.comcast.NET!not-for-mail
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.languages.vb:174695
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

"Steven Stein [MSFT]" said:
Slonocode -

The databound textbox is actually throwing an error that you can't catch.
You need to revert the currency back into a format that the db can handle.
(usually accomplished by removing the dollar sign ($, for example))


hope that helps

Steve Stein
VB Team

This posting is provided "AS IS" with no warranties and confers no
rights.

I thought I was converting back to decimal with the Parse event. Am I using
the Parse/Format correctly? Do I have to manually remove the "$"?


Private Sub oBidAmt_Format(ByVal sender As Object, ByVal e As
System.Windows.Forms.ConvertEventArgs) Handles oBidAmt.Format
e.Value = Format(e.Value, "c")
End Sub

Private Sub oBidAmt_Parse(ByVal sender As Object, ByVal e As
System.Windows.Forms.ConvertEventArgs) Handles oBidAmt.Parse
e.Value = Format(e.Value, "D")
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top