Hi
This works like a charm. Thank you.
How about if I want to display the 0 (when the value has it), but ""
when the value is fi. -999?
Basicly I want to user to be able to enter 0 and this should be
displayed. I init my properties to a default of -999 and if it is this
value, then the textbox should be empty, ie. "". Can this be done using
the formatstring argument? I haven't been able to find much info on
this parameter in MSDN.
Otherwise, thank you.
> Try this:
>
[quoted text clipped - 73 lines]
> >> > Regards
> >> > ...Seth Gecko- Skjul tekst i anførselstegn -- Vis tekst i anførselstegn -
RobinS - 26 Jan 2007 20:48 GMT
If you want to go to those lengths, you can use the Format
and Parse methods of the bound control. Try this:
in Form_Load:
'specifically bind the textbox for your field
'you have to do this, because you need the name of
' the databinding in order to capture the
' format and parse events
Dim myTextBoxBinding As Binding = _
New Binding("Text", myBindingSource, "myField", True)
'add event handlers for the format and parse events
AddHandler myTextBoxBinding.Format, AddressOf OnMyFieldFormat
AddHandler myTextBoxBinding.Parse, AddressOf OnMyFieldParse
myTextBox.DataBindings.Add(myTextBoxBinding)
Private Sub OnMyFieldFormat(ByVal sender As Object, _
ByVal e As ConvertEventArgs)
'ConvertEventArgs contains the [Value] that is to
' be used for setting the bound control property
' unless you decide to change it.
If e.Value Is Nothing OrElse e.Value.Equals(DBNull.Value) _
OrElse e.Value = -999 Then
'Show the textbox with nothing in it.
e.Value = String.Empty
End If
End Sub
Private Sub OnMyFieldParse(ByVal sender As Object, _
ByVal e As ConvertEventArgs)
'For the parse event, the Value property of the event argument
' contains the value of the bound control property. When
' the parsing process is complete, the value set on the [Value]
' property will be used to set the content of the bound column
' in the data source.
If stringValue = String.Empty Then
e.Value = -999
End If
End Sub
This is *also* from Brian Noyes' Data Binding book.
Robin S.
----------------------------------------------------------
Hi
This works like a charm. Thank you.
How about if I want to display the 0 (when the value has it), but ""
when the value is fi. -999?
Basicly I want to user to be able to enter 0 and this should be
displayed. I init my properties to a default of -999 and if it is this
value, then the textbox should be empty, ie. "". Can this be done using
the formatstring argument? I haven't been able to find much info on
this parameter in MSDN.
Otherwise, thank you.
> Try this:
>
[quoted text clipped - 81 lines]
> >> > ...Seth Gecko- Skjul tekst i anførselstegn -- Vis tekst i
> >> > anførselstegn -