for each control there are a lot of events, two are very similar such as Text Update and Text Changed, whis is the difference?
Here's my take on things, with sources from MSDN. I've used TextBox and ComboBox for my examples, however I'm fairly sure the logic generalizes.
TextUpdate:
Occurs when the control has formatted the text, but before the text is displayed. Use the TextUpdate event to validate the text before it is actually shown.
An example would be if a ComboBox is being populated from some datasource, and the data changes. This could trigger the TextUpdate event to allow for validation (or anything else).
http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.textupdate(v=vs.110).aspx
TextChanged:
Occurs when content changes in the text box. User input or setting the Text property to a new value raises the TextChanged event.
I think that quotation covers the example usage.
http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.textchanged(v=vs.95).aspx
I have just been playing around with this with the comboBox...
I found that the TextChanged event fires when the text is changed, eg user input or SelectedIndex changed.
TextUpdated event only fires when the user updates the text.
My program, I use Items.Add("x") to populate and SelectedIndex to select row. When user selected different item, the TextUpdated not fired. In TextUpdated, I have code to save the updated text as user is entering/changing it. You have to get the SelectedIndex from SelectionChangedCommitted and save it to a variable though as SelectedIndex within the TextUpdated appears to only return -1.
© 2022 - 2024 — McMap. All rights reserved.