What I need to do is to loop through all the TimeSlots in a DayView control and be able to determine for a given TimeSlot, who the Owner is. Is there any way to do this? I do not see any method or property on the TimeSlot itself that would lend a hand.
Or perhaps do I need to loop through some other collection to get to the TimeSlots for each Owner?
Any help would be greatly appreciated.
Is this a possible solution?
foreach (TimeSlot timeSlot in dvDay.TimeSlots) { string sOwnerKey = null; // Get the TimeSlotUIElement for this TimeSlot Infragistics.Win.UltraWinSchedule.DayView.TimeSlotUIElement tsElement = null; // Get the Context DayUIElement for the TimeSlotUIElement tsElement = dvDay.UIElement.GetDescendant(typeof(Infragistics.Win.UltraWinSchedule.DayView.TimeSlotUIElement), timeSlot);if (tsElement != null) {Infragistics.Win.UltraWinSchedule.DayView.DayUIElement dayElement = (Infragistics.Win.UltraWinSchedule.DayView.DayUIElement)tsElement.GetContext(typeof(Infragistics.Win.UltraWinSchedule.DayView.DayUIElement), true);if (dayElement != null) { // Get the Owner from the DayUIElement sOwnerKey = dayElement.Owner.Key; } } }
foreach (TimeSlot timeSlot in dvDay.TimeSlots)
{
string sOwnerKey = null;
// Get the TimeSlotUIElement for this TimeSlot
Infragistics.Win.UltraWinSchedule.DayView.TimeSlotUIElement tsElement = null;
// Get the Context DayUIElement for the TimeSlotUIElement
tsElement = dvDay.UIElement.GetDescendant(typeof(Infragistics.Win.UltraWinSchedule.DayView.TimeSlotUIElement), timeSlot);
// Get the Owner from the DayUIElement
sOwnerKey = dayElement.Owner.Key;
}
A TimeSlot object does not represent a physical manifestation, so there is no one-to-one relationship between an Owner and a TimeSlot; since the control can display multiple days as well as multiple owners, there is no one-to-one relationship between a TimeSlot and a date, either.
The TimeSlotUIElement, on the other hand, connects a TimeSlot with a date and optionally an Owner. The following code sample uses the DayUIElement and AllDayEventAreaDayUIElement elements to return the Owner at the specified client coordinates:
/// <summary>/// Returns the Owner at the specified point, or null if there/// is no Owner at the specified point./// </summary>/// <param name="dayView">The UltraDayView control to test.</param>/// <param name="point">The point the test, expressed in client coordinates.</param>private Owner OwnerFromPoint( UltraDayView dayView, Point point ){ UIElement controlElement = dayView != null ? dayView.UIElement : null; UIElement elementAtPoint = controlElement != null ? controlElement.ElementFromPoint( point ) : null; UIElement dayElement = null; UIElement allDayElement = null;
while ( elementAtPoint != null ) { dayElement = elementAtPoint as Infragistics.Win.UltraWinSchedule.DayView.DayUIElement; if ( dayElement != null ) break;
allDayElement = elementAtPoint as Infragistics.Win.UltraWinSchedule.DayView.AllDayEventAreaDayUIElement; if ( allDayElement != null ) break;
elementAtPoint = elementAtPoint.Parent; }
UIElement elementToCheck = dayElement != null ? dayElement : allDayElement;
return elementToCheck != null ? elementToCheck.GetContext( typeof(Owner) ) as Owner : null;}
Note that you could use the TimeSlotUIElement as well, although this example is more efficient because it does not require searching through as many elements as would be necessary when using TimeSlotUIElements.