mranzani

Hi all!

I'm experiencing a problem that I am not able to solve.
I have a databinded textbox that shows a date. So, I need to empty the texbox passing a null value. When I try to do that, after reloading the form, the textbox still shows the old date value.
How could I solve this issue

Many thanks in advance.


Re: Visual Basic Express Edition How to pass a null value to a date textbox?

Deepraj_Majumdar_35eaf1

Its happening because your text box is databind.Bind your text box at run time or use a event such as click or double click etc that fire a code which bind your text box at run time.




Re: Visual Basic Express Edition How to pass a null value to a date textbox?

mranzani

I tried to use the following with no success:

txt_Date.DataBindings.Clear()
txt_Date.DataBindings.Add("Text", TableNameBindingSource, "FieldName")




Re: Visual Basic Express Edition How to pass a null value to a date textbox?

mranzani

I solved using the following:

Dim myDate As Binding = Me.txt_Date.DataBindings(0)
AddHandler myDate.Parse, AddressOf OnParse

Private Sub OnParse(ByVal sender As Object, ByVal e As ConvertEventArgs)
If e.Value IsNot DBNull.Value Then
If e.Value = "" Then e.Value = DBNull.Value
End If
End Sub




Re: Visual Basic Express Edition How to pass a null value to a date textbox?

Bill Chen

Thanks mranzani,

I followed your method and successfully solved my problem, but actually I don't understand the concept, could you briefly explain or where can I found the related topics

Thanks again.

Bill





Re: Visual Basic Express Edition How to pass a null value to a date textbox?

Makis

use the following textbox
Public Class MyTextBox
Inherits TextBox

<Browsable(True), _
Bindable(True)> _
Public Property NullableText() As Object
Get
If Text.Trim.Length = 0 Then
Return DBNull.Value
Else
Return Text
End If
End Get

Set(ByVal Value As Object)
If Value Is DBNull.Value Then
Value = String.Empty
End If
Text = CStr(Value)
End Set
End Property
End Class

and bind your datetime datacolumn to NullableText property




Re: Visual Basic Express Edition How to pass a null value to a date textbox?

vndasc

You can not Bind a DBNull to a text box. You need to take care of if the database is returning NULL in whch case you dont put any thing as there is no data for the textbox.

Das