Event and EventArg data propagation though nested UserControls
-
I have a DayCell usercontrol class, which has a property Date (of type DateTime). I also have a MonthCal usercontrol which has a collection of DayCells. Finally, I have a YearCal usercontol which has a collection of MonthCals. I would like the YearCal to have a DateChanged event which is fired when a DayCell is clicked. I would like the Date property of the clicked Daycell to be made available to the YearCal client (via an EventArgs-derived parameter). I could create an event in MonthCal that is subscribed to by YearCal, which then fires the DateChanged event. There MUST be a more elegant way for the click event and date information to propagate from DayCell to MonthCal to YearCal, but for the life of me, I can't figure it out. I would be grateful for any suggestions. Thanks, tfhain
-
I have a DayCell usercontrol class, which has a property Date (of type DateTime). I also have a MonthCal usercontrol which has a collection of DayCells. Finally, I have a YearCal usercontol which has a collection of MonthCals. I would like the YearCal to have a DateChanged event which is fired when a DayCell is clicked. I would like the Date property of the clicked Daycell to be made available to the YearCal client (via an EventArgs-derived parameter). I could create an event in MonthCal that is subscribed to by YearCal, which then fires the DateChanged event. There MUST be a more elegant way for the click event and date information to propagate from DayCell to MonthCal to YearCal, but for the life of me, I can't figure it out. I would be grateful for any suggestions. Thanks, tfhain
Hi, if your YearCal holds say 12 MonthCals (lets hope it instantiates them by code, not by Visual Designer manipulations), then yes the proper way would be for it to subscribe to each MonthCal's Changed event and act upon it. It seems like you are creating almost 400 controls to represent one year's worth of calendar. That is a lot of stuff, and it is bound to paint rather slow, and react sluggish to all kinds of events (Form minimize/maximize/restore, repaints when uncovered, etc). I would recommend a more lightweight approach using maybe only one Control where you do all the painting explicitly, and the keyboard/mouse interaction by explicit code. It will probably result in less code (more hand-written code though) and far better performance. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
-
I have a DayCell usercontrol class, which has a property Date (of type DateTime). I also have a MonthCal usercontrol which has a collection of DayCells. Finally, I have a YearCal usercontol which has a collection of MonthCals. I would like the YearCal to have a DateChanged event which is fired when a DayCell is clicked. I would like the Date property of the clicked Daycell to be made available to the YearCal client (via an EventArgs-derived parameter). I could create an event in MonthCal that is subscribed to by YearCal, which then fires the DateChanged event. There MUST be a more elegant way for the click event and date information to propagate from DayCell to MonthCal to YearCal, but for the life of me, I can't figure it out. I would be grateful for any suggestions. Thanks, tfhain
In your current set up, that is the correct way IMO.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)