Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable DataSet Change Event?

Status
Not open for further replies.

MikeDamone

Programmer
Oct 21, 2003
106
US
I have a dataset that I want to disable the the change evernt handler long enough for me to format some numbers and then turn it back on after the format. Does anyone know how to do this? The dataset thinks there have been changes when I format the numbers, but its cosmetic changes that I don't wnat the user to be prompted to save on. Thanks
 
Set a boolean flag to indicate that the umbers are being formatted and don't execute any Change event code when that flag is True.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
I'm not positive on this one, but you'll probrably have to create a new class that inherits the datagrid class so that you can manage the handlers there, or do as jebenson suggests and use a boolean variable to determin wether or not to call the base datachanged event.

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Also, now that I think on it, what are you trying to do with the number formatting in the dataset? Is is just to display the numbers to the user? If so, you can avoid the Change event by applying the formats to whatever control is displaying the data (e.g., datagrid column, textbox, etc.). Since the formatting is being applied at the point of display rather than in the underlying dataset, the Change event won't fire.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Or you could format the values in the SQL Query/Stored Procedure (if you're using one) :)

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Thanks to everyone. Here's my dilemma. I used the dataform wizard to generate all the sql statements, and if you ever seen what it generates it's a mess to go in and format the numbers in the Select statement. If I had written it manually, that's what I would have done.

I am not trying to format the numbers in the dataset, but rather in the text boxes that the dataset is bound to. The probelm is I can format the numbers without the change event firing, but when the user clicks in the the textbox, I want the formatting to be removed. When I remove the formatting is when the dataset thinks changes have ocurred. So what I want to do, is disable the change event handler on enter in the text box, remove the formatting, and then turn the event handler back on. By the way, this is a windows application. Any ideas? Thanks
 
I would recommend against using the data wizard and binding data directly to the GUI. But that's just me ;)

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Thanks for the help. I got it to work, but not with the event handlers. I turned off the databindings on enter to the textbox long enough to remove the formatting and then turned the databindigs right back on.

Me.textbox1.DataBindings.Clear()
Me.textbox1.Text = CType(Me.textbox1.Text, Decimal)

Me.textbox1.DataBindings.Add("Text",Me.dataset1, "table1.field1")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top