AMDRIT
Wed Aug 03 12:05:57 CDT 2005
I made a simple test to reproduce my issue:
Create a windows application
Create a new dataset, one table, two fields (RowID Int(Auto, -1,-1);
SomeDate Date)
Add a commandbutton and a textbox to form1
Paste in the following form code:
Private m_dsTest As Dataset1
Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnTest.Click
Try
Dim dr As Dataset1.SimpeTableRow
Dim b As Binding
dr = m_dsTest.SimpeTable.NewSimpeTableRow
m_dsTest.SimpeTable.AddSimpeTableRow(dr)
b = New Binding("Text", dr, "SomeDate")
AddHandler b.Parse, AddressOf DBdateTextbox
'DataBindingManager.CurrencyStringtoDate
AddHandler b.Format, AddressOf TextBoxDBdate
'DataBindingManager.DateToCurrencyString
Me.txtDate.DataBindings.Add(b)
Catch ex As System.Reflection.TargetInvocationException
Debug.WriteLine("Boom!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" & vbCrLf &
ex.ToString)
Stop
Catch ex As Exception
Debug.WriteLine(ex.ToString)
End Try
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
m_dsTest = New Dataset1
End Sub
Private Sub DBdateTextbox(ByVal sender As Object, ByVal cevent As
ConvertEventArgs)
If cevent.Value Is DBNull.Value Then
cevent.Value = ""
Else
Dim datum As Date
datum = CDate(cevent.Value)
cevent.Value = datum.ToString("d")
End If
End Sub
Private Sub TextBoxDBdate(ByVal sender As Object, ByVal cevent As
ConvertEventArgs)
If cevent.Value.ToString = "" Then
cevent.Value = DBNull.Value
Else
Dim datum As Date
datum = CDate(cevent.Value)
Cevent.Value = datum
End If
End Sub
................. Data set XML.................
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="Dataset1" targetNamespace="
http://tempuri.org/Dataset1.xsd"
elementFormDefault="qualified"
attributeFormDefault="qualified" xmlns="
http://tempuri.org/Dataset1.xsd"
xmlns:mstns="
http://tempuri.org/Dataset1.xsd"
xmlns:xs="
http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Dataset1" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="SimpeTable">
<xs:complexType>
<xs:sequence>
<xs:element name="RowID" type="xs:int" minOccurs="0"
msdata:AutoIncrement="true" msdata:AutoIncrementSeed="-1"
msdata:AutoIncrementStep="-1" />
<xs:element name="SomeDate" type="xs:date" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:key name="Dataset1Key1">
<xs:selector xpath=".//mstns:SimpeTable" />
<xs:field xpath="mstns:RowID" />
</xs:key>
</xs:element>
</xs:schema>
"AMDRIT" <amdrit@hotmail.com> wrote in message
news:ubqqThEmFHA.4000@TK2MSFTNGP12.phx.gbl...
>
> Cor,
>
> Thanks for the response. My code is similare to what you have, and I am
> still getting this exception:
>
> An unhandled exception of type
> 'System.Reflection.TargetInvocationException' occurred in system.dll
>
> Additional information: Property accessor 'ExpirationDate' on object
> 'DelphiCommercial.DataDictionary+ApplicationsRow' threw the following
> exception:'Cannot get value because it is DBNull.'
>
>
> It doesn't appear to get to ever get to the format handler.
>
> Here is what I have in place:
>
> ... form code ...
>
> b = New Binding("Text", dr, "ExpirationDate")
> AddHandler b.Parse, AddressOf DataBindingManager.CurrencyStringtoDate
> AddHandler b.Format, AddressOf DataBindingManager.DateToCurrencyString
> Me.txtExpirationDate.DataBindings.Add(b)
>
> ... DataBindingManager ...
>
> Public Shared Sub DateToCurrencyString(ByVal sender As Object, ByVal e As
> System.windows.forms.ConvertEventArgs)
>
> Trace.WriteLineIf(Globals.ThisTrace.TraceVerbose, "begin date binding
> formating")
>
> If e.Value Is System.DBNull.Value Then
> e.Value = ""
> Else
> e.Value = CType(e.Value, Date).ToShortDateString.ToString
> End If
>
> Trace.WriteLineIf(Globals.ThisTrace.TraceVerbose, "end date binding
> formating")
>
> End Sub
>
> Public Shared Sub CurrencyStringtoDate(ByVal sender As Object, ByVal e As
> System.windows.forms.ConvertEventArgs)
>
> Trace.WriteLineIf(Globals.ThisTrace.TraceVerbose, "date parsing")
>
> If e.Value.ToString = "" Then
> e.Value = DBNull.Value
> Else
> e.Value = CDate(e.Value)
> End If
>
> Trace.WriteLineIf(Globals.ThisTrace.TraceVerbose, "end date parsing")
>
> End Sub
>
>
>
> "Cor Ligthert [MVP]" <notmyfirstname@planet.nl> wrote in message
> news:<uwsKdjDmFHA.1464@TK2MSFTNGP14.phx.gbl>...
>> ADmdrit,
>>
>> Have a look at this sample on our website, the textbox binding has to be
>> of course to a strongly typed dataset/datatable column.
>>
>>
http://www.windowsformsdatagridhelp.com/default.aspx?ID=c4832a2a-2b95-4ded-93d9-4deb7fa4a0b8
>>
>> I hope this helps,
>>
>> Cor
>>
>