Confused by events
-
I have a windows app and on form_load i am calling a funciton that is building a list but this function gets called on other ocassions also (when there is change in data (i.e. add, update or delete)). I want to raise an event when I have the item.Name available so I can populate the drop down box with the item names. So essentially I want an OnItemLoad event to be fired and when its fired I want the drop down box to populate the items.
for (int i = 0; i < Category.Length; i++) { #region This section needs to be replaced by the event if (populateCategoryDropDownList) { ddlCategory.Items.Add(Category[i].CategoryName); } #endregion ... txtControl.AutoCompleteCustomSource.Add(temp); ... }
I have tried working with examples available on msdn etc but it gets soo confusing! this seem like a very simple task but I just can't seem to figure it out. Please help !
-
I have a windows app and on form_load i am calling a funciton that is building a list but this function gets called on other ocassions also (when there is change in data (i.e. add, update or delete)). I want to raise an event when I have the item.Name available so I can populate the drop down box with the item names. So essentially I want an OnItemLoad event to be fired and when its fired I want the drop down box to populate the items.
for (int i = 0; i < Category.Length; i++) { #region This section needs to be replaced by the event if (populateCategoryDropDownList) { ddlCategory.Items.Add(Category[i].CategoryName); } #endregion ... txtControl.AutoCompleteCustomSource.Add(temp); ... }
I have tried working with examples available on msdn etc but it gets soo confusing! this seem like a very simple task but I just can't seem to figure it out. Please help !
What is "item.Name"? Do you need an event, or do you just need to call the method that builds your list from other events, like Load?
only two letters away from being an asset
-
What is "item.Name"? Do you need an event, or do you just need to call the method that builds your list from other events, like Load?
only two letters away from being an asset
Sorry, Item.Name = Category[i].CategoryName Item being a drop down list item. This can be done with a call to a method but there is some other stuff that can be accomplished once I have a specific category available. I tried to omit the details out to keep the question simple. But for argument's sake, for each category there are several other child records that need to get processed. Some of them are shown on the UI and some of them are more like calculation type results. I thought using event would simplify the process and would also increase the performance (not sure if this is true) by completing the task on a separate thread. Thanks
-
Sorry, Item.Name = Category[i].CategoryName Item being a drop down list item. This can be done with a call to a method but there is some other stuff that can be accomplished once I have a specific category available. I tried to omit the details out to keep the question simple. But for argument's sake, for each category there are several other child records that need to get processed. Some of them are shown on the UI and some of them are more like calculation type results. I thought using event would simplify the process and would also increase the performance (not sure if this is true) by completing the task on a separate thread. Thanks
Events are an implementation of the observer pattern. They are used to notify an interested party that something has happen to an object that they have expressed an interest in knowing about. Events don't increase performance, however, can certainly decrease it if not used properly. From what I can see from you description you don't need to use events. You should also do more research before trying to use a technique you are unfamiliar with. Learn when and why to use, and when not to use it.
only two letters away from being an asset