Why is my bound form not clearing?!?!

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am having some strange behavior trying to clear some textboxes on a form
that is bound to a datatable. The bizarre thing is that I have about 10
bound text boxes on my form, but I am only having trouble with two of them.
I have a button on my form, that when pushed, needs to clear the contents of
all the fields. So I enter values in all my textboxes and use the following
code to clear the textboxes.


For i = 0 To Me.Controls.Count - 1

If TypeOf (Me.Controls(i)) Is TextBox Then
Me.Controls(i).Text = Nothing
End If

Next

At this point, all the values clear from the form. But, when I End the
Current Edit via...

Me.BindingContext(datatable).EndCurrentEdit()

Two of my textboxes reinsert the values they had in there before they were
cleared, all of the other textboxes clear fine. I have tried renaming the
textboxes, deleting and reinserting them, nothing seems to work. Same two
textboxes everytime. For that matter, I try to clear the contents using the
SIP, but the numbers will not go away. Anybody have any suggestions?

Thanks!

Mike
 
Consider clearing the data source instead.



Best regards,



Ilya



This posting is provided "AS IS" with no warranties, and confers no rights.
 
OK, I have figured out that the two fields I am having trouble with just
happen to be Numeric DataTypes. It appears that a Numeric Datatype cannot be
Nothing or "" which is why it keeps reseting back to the value before it was
cleared. Therefore, my question just became a bit simpler.....

How do I assign a numeric textbox a value of nothing?

Thanks!

Mke
 
Thanks guys. I'm trying to figure out exactly what you are suggesting in
clearing the data source. I cant clear my datatable because I need that data
to remain loaded. I cant delete the row, because I still need to enter some
data for that row. Could you provide a quick code snippet as to what you
were envisioning? Thanks!
 
I'm not suggesting deleting data from the data table or deleting the current
row.
I'm suggesting setting data in the current row to DBNull or some defaults.

Something like this:

Dim bmb As BindingManagerBase = Me.BindingContext(datatable)
Dim drv As DataRowView = CType(bmb.Current, DataRowView)


drv(0) = DBNull.Value ' Or set to default value
....

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks Ilya. I see what you are saying now. It appears to work great!

FYI-strange thing, I cant see your posts via the MSDN Usenet group,
just via the Google groups? I can see everyone else's just not yours?

Anyway, thanks for the input!
 
Back
Top