Question commit record on text changed


New member
Sep 20, 2013
Programming Experience
Hi all,

I am having a massive issue trying to figure out how I can call the savebutton_click() method when the text changes for any of the fields.

I tried to override the Field_textchanged to call the saveButton_click() function. But can't do it.

I have a base class (that saves and does all the fancy things) I need to call that method when text changes. My code:

Protected Sub field_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles field.TextChanged
me.saveButton_click_base() ' given an error

I tried doing

Me.savedate () 'this also gave error

end sub

I can't think of why I can't call these methods?

Is there a way I can solve this problem? Help!!


I would suggest that you are getting these errors due to the fact that you are trying to save your Data using the TextChanged event of your control. Consider this:-

If you are trying to construct a Date in a TextBox control and the Type of the destination field in your DataSource is a Date or DateTime then you are going to cause yourself errors since as soon as you type the first character, lets say 1, you will then try and save it and as you can see the number 1 is not a valid date, hence an error will occur. This is just one example of why this is a bad idea, not to mention the unnecessary use of resources, Database Access and potential Network Traffic every time you pressed a key.

Another bad suggestion would be to save your Data after each control is changed using the Control.Validated event to initiate the save. At least that way you would know that the data in each control is valid for each bit of information you are trying to save to the DataSource.

That said, don't do any of that, and come up with a way to identify when a Record has changed and then save your Record, once only, after you have finished using that record.

Then again, don't do that either, and come up with some similar logic to identify when you have finished using your DataTable and then save all your changes in one go back to your DataSource using the Update Method of a TableAdapter or DataAdapter.

Hope that helps.



Latest posts