Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Programmatically move to a time span in ResourceView (Read 2574 times)
Achim
Junior Member
**
Offline


MindFusion rocks!

Posts: 70
Location: Bayreuth, Germany
Joined: Jun 28th, 2012
Programmatically move to a time span in ResourceView
Jan 14th, 2013 at 1:27pm
Print Post  
Hi there,

I'm experiencing a - maybe trivial - problem in the ResourceView:

Let's assume I have a total time range from January 1st 2013 to July 15th 2013. When the user opens the gantt chart I want to show exactly the view from February 6th to February 10th. I tried to set Date and EndDate but it seems to have no effect at all.

I know that setting a very small time span would lead to a TimeLineScale factor greater than 1000 (which is the current limit) but I hope it's possible anyway. Maybe the limit for the TimeLineScale is not so important and the value could be larger...

Best regards
Achim
  
Back to top
WWW  
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Programmatically move to a time span in ResourceView
Reply #1 - Jan 14th, 2013 at 2:16pm
Print Post  
The following code scrolls and scales the view so that the interval [Feb 6th, Feb 10th] is visible and spans the entire visible area of the control:

Code
Select All
DateTime targetStartDate = new DateTime(2013, 2, 6);
DateTime targetEndDate = new DateTime(2013, 2, 10);
TimeSpan targetSpan = targetEndDate - targetStartDate;

calendar.EnsureVisible(targetStartDate);

// EnsureVisible does not guarantee that the target date will be at
// the start of the displayed interval, more specifically, if the
// target date is already visible, EnsureVisible does nothing; so
// perform a step-by-step scrolling until the target date is at the start
while (calendar.GetFirstVisibleDate() < targetStartDate)
	calendar.HScrollPos++;

// ...or if you don't need the scroll, you can skip the previous code
// and directly assign targetStartDate and targetEndDate to the Calendar.Date
// and Calendar.EndDate properties
//calendar.Date = targetStartDate;
//calendar.EndDate = targetEndDate;

DateTime first = calendar.GetFirstVisibleDate();
DateTime last = calendar.GetLastVisibleDate();
TimeSpan visibleSpan = last - first;
if (visibleSpan.Ticks == 0)
	return;

double availableWidth = calendar.Width - calendar.ResourceViewSettings.RowHeaderSize;
double pixelsPerTick = availableWidth / visibleSpan.Ticks;
double desiredPpt = availableWidth / targetSpan.Ticks;
double scale = desiredPpt / pixelsPerTick;
scale *= calendar.ResourceViewSettings.TimelineScale;
if (scale < 10)
	scale = 10;
if (scale > 1000)
	scale = 1000;

calendar.ResourceViewSettings.TimelineScale = (int)scale; 



The code still regards the limitation of the TimelineScale property however, so if the final scale is larger than 1000, the scaling won't work properly. There is no elegant way to work around this restriction so it needs to be increased (or removed) in the control's source code.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint