PC Review


Reply
Thread Tools Rate Thread

binding format

 
 
Michael Roberts Jr
Guest
Posts: n/a
 
      7th Aug 2003
I am having trouble with a binding that was created to format a textbox on a
form. I have created a format procedure that takes a date and makes a
string, so that it can be displayed as a short date.

Private Sub DatetoShort(ByVal sender As Object, ByVal cevent As
ConvertEventArgs)
' The method converts only to string type. Test this using the DesiredType.

If Not cevent.DesiredType Is GetType(String) Then

Exit Sub

End If

' Use the ToshortDate method to format short date

Try ' if date is null then catch

cevent.Value = CType(cevent.Value, Date).ToShortDateString

Catch

End Try

End Sub


The problem I have is that I can't figure out how to get the value to go to
null if the date needs to be erased. For example, a date of birth might not
be available. If it is not entered into the database with a new record then
there is no problem. But then if I change the value and give it a date. I
can't erase the date later. The code for the textbox is as follows:
' Create the binding date of birth

Dim bBirthdate As Binding = New Binding _

("Text", Me.objAlphaStudent, "DERecords.birthdate")

' Add the delegates to the event

AddHandler bBirthdate.Format, AddressOf DatetoShort

txtbDOB.DataBindings.Add(bBirthdate)

If I try to reset the textbox.text property to "" it just reverts back to
whatever date was entered and accepted. What can I do to erase the field
(set it to null) after a valid date has been entered?




 
Reply With Quote
 
 
 
 
Per-Frode Pedersen
Guest
Posts: n/a
 
      25th Aug 2003
Add a parse event handler, something like this:

Dim bBirthdate As Binding _
= New Binding ("Text", Me.objAlphaStudent, "DERecords.birthdate")

AddHandler bBirthdate.Format, AddressOf DatetoShort
txtbDOB.DataBindings.Add(bBirthdate)

Private Sub DatetoShort(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)

If cevent.Value = "" Then
cevent.Value = DBNull.Value
Else
cevent.Value = DateTime.Parse(cevent.Value)
End If

End Sub

Per-Frode Pedersen

"Michael Roberts Jr" <(E-Mail Removed)> wrote in message news:<zLlYa.249618$(E-Mail Removed)>...
> I am having trouble with a binding that was created to format a textbox on a
> form. I have created a format procedure that takes a date and makes a
> string, so that it can be displayed as a short date.
>
> Private Sub DatetoShort(ByVal sender As Object, ByVal cevent As
> ConvertEventArgs)
> ' The method converts only to string type. Test this using the DesiredType.
>
> If Not cevent.DesiredType Is GetType(String) Then
>
> Exit Sub
>
> End If
>
> ' Use the ToshortDate method to format short date
>
> Try ' if date is null then catch
>
> cevent.Value = CType(cevent.Value, Date).ToShortDateString
>
> Catch
>
> End Try
>
> End Sub
>
>
> The problem I have is that I can't figure out how to get the value to go to
> null if the date needs to be erased. For example, a date of birth might not
> be available. If it is not entered into the database with a new record then
> there is no problem. But then if I change the value and give it a date. I
> can't erase the date later. The code for the textbox is as follows:
> ' Create the binding date of birth
>
> Dim bBirthdate As Binding = New Binding _
>
> ("Text", Me.objAlphaStudent, "DERecords.birthdate")
>
> ' Add the delegates to the event
>
> AddHandler bBirthdate.Format, AddressOf DatetoShort
>
> txtbDOB.DataBindings.Add(bBirthdate)
>
> If I try to reset the textbox.text property to "" it just reverts back to
> whatever date was entered and accepted. What can I do to erase the field
> (set it to null) after a valid date has been entered?

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
vb.net early binding coding format douglas Microsoft VB .NET 4 7th Apr 2009 03:34 PM
ASP .NET Binding with Format {0:N0} is one way only jehugaleahsa@gmail.com Microsoft C# .NET 4 27th Feb 2008 03:13 PM
binding format Keith G Hicks Microsoft ASP .NET 3 12th Feb 2008 05:11 AM
Binding.Format not alway being called Joe Microsoft ADO .NET 2 2nd Nov 2006 06:35 PM
Binding Format event bjoseluisb Microsoft Dot NET Compact Framework 0 3rd Dec 2003 06:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:53 AM.