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.
Ah I see. What I am trying to accomplish is for each Owner to be able to each have their own "availability" defined. I would like to for a given date/time and owner, color the background of the TImeSlotUIElements to some color to indicate this availability status.
So I guess what I need to do is to loop through the visible TimeSlotUIElements for each Owner and to color them accordingly. What would be the best way to find the TimeSlotUIElements per Owner? I have tried something like:
DayView.UIElement.GetDescendant(typeof(Infragistics.Win.UltraWinSchedule.DayView.TimeSlotUIElement), new object[ { targetTimeSlot, targetOwner} );
But this seems to always return null. What would be the proper way to get at the TimeSlotUIElement in this case?
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.
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;
}