I am using a bindingsource whose datasource is set to a Datatable that is loaded from the database. The columns for integer and float in the database have default values assigned as 0. The query returns either 0 or the actual value for those columns.
I have several Textboxes bound to integer columns and also float columns. My Textboxes that are bound to the float columns show 0 when ever there is a 0 value. My Integer Textboxes show EMPTY when there is a 0 value. I want it to show 0.
EDIT For the Down Vote and Vote to Close. I have seen examples on SO dealing with this issue - some declare to set it in the datatable - which I used that example in my code and it has not changed the result - I type zero in my text box and the box goes blank, I type 1 and it takes it. I know the issue has something to do with what it is bound to. It is an Integer type which is not really nullable - I know you can. So why is it when I type 0 the box goes blank, but if I type 1 it stays. I know the value gets updated whether 0 or whatever. But why the difference between Single and Integer ? Single Works using the same Exact code, Integer does not. Please explain. I read here and other places. How to set default values for data bound controls for addition in VB.NET
EDIT I can paste a value 1.25 in to my Textbox with single values, and it works but I cannot type a value of 1.25 in , when I press the decimal point the cursor automatically moves back to the first character position.
I am not sure why this occurs - I do update the source from the text changed event. I have a flag set though when I enter the textbox IsEditing = True. So the text change event is only effective when the user enters the textbox. I do not understand why this happens - I know it is in the databinding but I do not know what to change to fix it.
My Relevant Code is.
Private Sub LoadTable()
dtBins = DatabaseFetch
SetDefaults()
AddBindings()
End Sub
Private Sub SetDefaults
Dim columnDefs As String() = New String()
{"Fill_Part", "Fill_Pulse", "Fill_Fails", "Fill_Value"}
For i As Integer = 0 To columnDefs.Length - 1
If dtBins.Columns.Contains(columnDefs(i)) Then
dtBins.Columns.Item(columnDefs(i)).DefaultValue = 0
End If
Next
End Sub
Private AddBindings()
bindingtxtFillPulse = New System.Windows.Forms.Binding("Text",
bsBins,
"Fill_Pulse",
True,
DataSourceUpdateMode.OnPropertyChanged)
bindingtxtFillPulse.NullValue = 0
bindingtxtFillPulse.DataSourceNullValue = 0
Me.txtFillPulse.DataBindings.Add(bindingtxtFillPulse)
End Sub