Hi,

I have bound a DateTime field in a DataTable to a TextBox field. Other
String and Numeric fields are also bound to separate TextBoxes. If a new
DataRow is created and a DateTime value is entered no problem. However,
after the row is saved, I am unable to clear the date from the textbox.

I do not have this problem when binding to a DataGrid. But a DataGrid is
far from user friendly and just plain impractical in many situations.

In its place I am loading the DataRow into a class and using unbound fields
on the form. Bound controls seem great for strings. But thats about it.
Does anyone have a better solution?

Thanks

Re: DateTime Bound to TextBox by Sijin

Sijin
Wed Dec 01 02:59:58 CST 2004

Try writing Format and Parse event handlers for the binding to convert
empty string to empty datetime

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWindowsFormsBindingClassFormatTopic.asp

http://www.akadia.com/services/dotnet_databinding.html#Format%20and%20Parse%20Events%20of%20the%20Binding%20Class
http://www.eggheadcafe.com/ng/microsoft.public.dotnet.framework.windowsforms.databinding/post109933.asp

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

mark wrote:
> Hi,
>
> I have bound a DateTime field in a DataTable to a TextBox field. Other
> String and Numeric fields are also bound to separate TextBoxes. If a new
> DataRow is created and a DateTime value is entered no problem. However,
> after the row is saved, I am unable to clear the date from the textbox.
>
> I do not have this problem when binding to a DataGrid. But a DataGrid is
> far from user friendly and just plain impractical in many situations.
>
> In its place I am loading the DataRow into a class and using unbound fields
> on the form. Bound controls seem great for strings. But thats about it.
> Does anyone have a better solution?
>
> Thanks
>

Re: DateTime Bound to TextBox by mark

mark
Thu Dec 02 12:25:01 CST 2004

Sijin,
I'm a bit confused about the meaning of an empty DateTime.
Are you saying set this field to DBNull in the Parse event? Because
a DateTime cannot be set to null. The runtime throws an error.
Thanks

"Sijin Joseph" wrote:

> Try writing Format and Parse event handlers for the binding to convert
> empty string to empty datetime
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWindowsFormsBindingClassFormatTopic.asp
>
> http://www.akadia.com/services/dotnet_databinding.html#Format%20and%20Parse%20Events%20of%20the%20Binding%20Class
> http://www.eggheadcafe.com/ng/microsoft.public.dotnet.framework.windowsforms.databinding/post109933.asp
>
> Sijin Joseph
> http://www.indiangeek.net
> http://weblogs.asp.net/sjoseph
>
> mark wrote:
> > Hi,
> >
> > I have bound a DateTime field in a DataTable to a TextBox field. Other
> > String and Numeric fields are also bound to separate TextBoxes. If a new
> > DataRow is created and a DateTime value is entered no problem. However,
> > after the row is saved, I am unable to clear the date from the textbox.
> >
> > I do not have this problem when binding to a DataGrid. But a DataGrid is
> > far from user friendly and just plain impractical in many situations.
> >
> > In its place I am loading the DataRow into a class and using unbound fields
> > on the form. Bound controls seem great for strings. But thats about it.
> > Does anyone have a better solution?
> >
> > Thanks
> >
>