dotnet compact framework:
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. [quoted text, click to view] "Mike" <Mike@discussions.microsoft.com> wrote in message news:84D3E604-72F6-4F4D-A828-5F9C51B180B5@microsoft.com... >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 > >
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 [quoted text, click to view] "Mike" wrote: > 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 >
As Ilya suggested, clear the data source. -Chris [quoted text, click to view] "Mike" <Mike@discussions.microsoft.com> wrote in message news:D1F00E04-7E02-4DA9-AD1F-AF4425759B98@microsoft.com... > 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 > > "Mike" wrote: > >> 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 >> >>
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! [quoted text, click to view] "<ctacke/>" wrote: > As Ilya suggested, clear the data source. > > -Chris > > "Mike" <Mike@discussions.microsoft.com> wrote in message > news:D1F00E04-7E02-4DA9-AD1F-AF4425759B98@microsoft.com... > > 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 > > > > "Mike" wrote: > > > >> 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 > >> > >> > >
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. [quoted text, click to view] "Mike" <Mike@discussions.microsoft.com> wrote in message news:80C4B275-2F4A-42BA-8A0E-AEA54C972565@microsoft.com... > 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! > > > > > "<ctacke/>" wrote: > >> As Ilya suggested, clear the data source. >> >> -Chris >> >> "Mike" <Mike@discussions.microsoft.com> wrote in message >> news:D1F00E04-7E02-4DA9-AD1F-AF4425759B98@microsoft.com... >> > 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 >> > >> > "Mike" wrote: >> > >> >> 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 >> >> >> >> >> >> >>
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! [quoted text, click to view] Ilya Tumanov [MS] wrote: > 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. > > "Mike" <Mike@discussions.microsoft.com> wrote in message > news:80C4B275-2F4A-42BA-8A0E-AEA54C972565@microsoft.com... > > > 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! > > > > > > > > > > "<ctacke/>" wrote: > > > >> As Ilya suggested, clear the data source. > >> > >> -Chris > >> > >> "Mike" <Mike@discussions.microsoft.com> wrote in message > >> news:D1F00E04-7E02-4DA9-AD1F-AF4425759B98@microsoft.com... > >> > 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 > >> > > >> > "Mike" wrote: > >> > > >> >> 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 > >> >> > >> >> > >> > >> > >>
Don't see what you're looking for? Try a search.
|