473,513 Members | 2,493 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create event c# (not invoke or define)

Hi, I need to create a NEW event on c#: I need to execute a command when a local variable CHANGES, I know how to define, execute, etc events that are already stored in VS (buttonClicked,etc...) Is there a simple way to do this?
Many thanks for your time.
Oct 29 '10 #1
3 3207
Leito
58 New Member
I don't know any mean to do that, but there should be a defined event (like buttonClicked...) that triggers the change of your local variable, isn't it ?
Nov 3 '10 #2
Christian Binder
218 Recognized Expert New Member
You an't trigger an event when a local variable changes, but you can use a property instead of a local variable and there you can trigger the event.

Expand|Select|Wrap|Line Numbers
  1. //Define the event
  2. event Action LocalVarChanged;
  3.  
  4. int _localVar = 0;
  5.  
  6. //Create a property for your local var
  7. LocalVar {
  8.   get { return _localVar; }
  9.   set {
  10.     _localVar = value;
  11.     //Trigger the event
  12.     if(event != null)
  13.       event();
  14.   }
  15. }
  16.  
Nov 3 '10 #3
Curtis Rutland
3,256 Recognized Expert Specialist
Christian's answer is exactly how to do this, if you want a specific event for a specific property.

If you want a single event for all your properties (with the EventArgs telling you which property changed), there's already an interface designed to do this for you: INotifyPropertyChanged.

Implementing that interface properly, and adding the invocation code to all your properties, will let you catch when any property changes, and react appropriately. This is useful for objects that will be used in ObservableCollections.
Nov 4 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4281
by: db2group88 | last post by:
hi, we install db2 udb v8.1 on windows 64bit, in our application, we have sql execute "create table .... not logged initially", but from the operating system event viewer showing error stating that...
13
2054
by: Richard W | last post by:
I have a very simple web page (ASP.NET) that I am trying to build. On the web page is a checkbox that enables or disables other controls based upon the checked status. However, .NET fails to...
2
1131
by: jeff_mishima | last post by:
Hello, I've got an issue with a dynamically assigned event not actually being assigned correctly to a linkbutton- or at least that appears to be the issue. The linkbutton doesn't work on 1st...
2
3356
by: Deepesh | last post by:
Good day, I have a specific case of the DataGrid in my solution which is causing the ItemCommand Event Not Firing. So I'm creating a "Skinnable" set of controls. I seperate the actual ASCX file...
4
4137
by: EvelynAnd Ethan | last post by:
Hi, ItemCommand event not firing from a dynamic user control ,WHERE A DATAGRID HAS BUTTON,when i click on the linkbutton first time the itemcommand event doesnt fire,second time event fires up ...
2
2454
by: chris in grimsby | last post by:
MDIChild Window Closing event not raised when MDI Parent is in a class library! Intructions to recreate problem: 1. Create a ClassLibrary project 2. Add an MDIParent form and a form that will...
0
960
by: Shane Story | last post by:
I have a file system watcher. It is watching one directory where faxes come in. These faxes are written by another software program. The create event seems to fire and then we get an error...
6
28100
by: Kevin Attard | last post by:
I am using a GridView inside a UserControl which has a template column for deleting the rows. Before databinding the gridview i am attaching the RowCommand and RowDataBound event. I am using the...
0
1432
by: Artur | last post by:
After trying to solve this, I noticed another strange thing. When in secure connection Page_Load method of page is not invoked (Load event not fired). I looked where this method is assigned to this...
2
2817
by: =?Utf-8?B?Uml0YUc=?= | last post by:
I posted this question in the C# discussion group but am posting it here also since ASP is involved. I'm new to C# and need some help regarding an onClick event not firing. I have a data grid...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7161
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5089
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.