Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
is there any event in windows form application that tells me that a value of one component changed since i opened this form
if there is none do you have a function that handles that
note:iam using datacontext and bind the components to it does that serve me
in knowing any change in control
Posted
Updated 30-Dec-14 0:50am
v3
Comments
BillWoodruff 30-Dec-14 8:01am    
I think you need to define "components changed" in more detail. What are the components, what type of whatever gets changed ?

Have you looked at .NET features like ObervableCollection ?
oula alsheikh 30-Dec-14 8:22am    
textboxes and comboboxes
BillWoodruff 30-Dec-14 8:39am    
Please comment on what Properties of TextBoxes and ComboBoxes you wish to monitor ? Do you wish to monitor just the act of clicking ... giving focus to ... these Controls ? To monitor the time elapsed where each Control was the 'ActiveControl of the Form ?

It is "natural" to guess you may want to record when the user clicks an Item in the ComboBox, or, perhaps, presses the 'Enter key in the TextBox, but it is always best to know what you want, rather than guess.

Have you started writing any code ?
oula alsheikh 31-Dec-14 3:15am    
i have a form having components (textboxes,comboboxes)
these components are bound to table in a datacontext through
binding source
i want to know if any change occurs to text property of textbox without handling each textbox
what should i use ?what about PropertyChangedEventHandler
does it handles my situation
or i should iterate through textboxes and define event handler for textchanged?

1 solution

With ComboBox, this is easy. You can handle these events, some or all of them, depending on what you need:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.textchanged(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.textchanged(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.selectedindexchanged(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.listcontrol.selectedvaluechanged(v=vs.110).aspx[^].

With TextBox, handle this event: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.textchanged(v=vs.110).aspx[^].

Now, you can recursively traverse all the controls, use as dynamic cast operator on each control, to get controls of required types, and add the event handler to each. You will find my code sample doing something similar in my past answer: C# How To Subscribe To An Event For Each Control In A Form?[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900