Hi,
>I am wondering if there is a better solution, than the one I came up
> with...
[quoted text clipped - 26 lines]
>
> Is there a better way?
There are other ways, you decide what you like most:
1) Since it looks like you are inheriting the TextBox, you could override
Text instead, eg. :
public override string Text
{
get
{
return ((base.Text=="") && !DesignMode)? null : base.Text;
}
set
{
base.Text = value;
}
}
2) Instead of inheriting from TextBox, you could attach an eventhandler to
the DataBinding Parse event, eg. :
// if you have setup the bindings using the designer then attach the
eventhandler
// after InitializeComponent
textBox1.DataBindings.Add("Text", yourBindingSource, "yourField");
textBox1.DataBindings["Text"].Parse += new ConvertEventHandler(
StringToFloatHandler );
private void StringToFloatHandler (object sender, ConvertEventArgs e)
{
string str = e.Value as string;
e.Value = (str=="")? (float?)null : float.Parse(str);
}
HTH,
Greetings
AnikSol - 26 Oct 2006 14:45 GMT
Hi Bart,
Any chance that you could post your suggestions 1 and 2 in VB?
thanks n regards
> Hi,
>
[quoted text clipped - 64 lines]
> HTH,
> Greetings
Bart Mermuys - 26 Oct 2006 21:24 GMT
Hi,
> Hi Bart,
>
> Any chance that you could post your suggestions 1 and 2 in VB?
I'm not very familar with nullable types in VB, but it here it goes:
1)
Public Overrides Property Text() As String
Get
Return IIf((MyBase.Text = "") And Not DesignMode, Nothing, MyBase.Text)
End Get
Set(ByVal value As String)
MyBase.Text = value
End Set
End Property
2)
AddHandler TextBox1.DataBindings("Text").Parse, AddressOf
StringToFloatHandler
Private Sub StringToFloatHandler( ByVal sender As Object, ByVal e As
ConvertEventArgs )
Dim str As String = CStr( e.Value )
e.Value = IIf(str = "", Nothing, float.Parse(str) )
End Sub
HTH,
Greetings
> thanks n regards
>
[quoted text clipped - 66 lines]
>> HTH,
>> Greetings
AnikSol - 27 Oct 2006 03:04 GMT
Bart
Thanks.
> Hi,
>
[quoted text clipped - 100 lines]
>>> HTH,
>>> Greetings