Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic ResourceView: changing the selection style (Read 3457 times)
ismar.slomic
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Jun 14th, 2009
ResourceView: changing the selection style
Jun 14th, 2009 at 9:03pm
Print Post  
Hi,
is it possible to actually select particular cell when doing a selection in the resourceview.

Like in the Timetable, when you click on particular cell it gets selected, and when you press the mouse button and drag, each cells get selected.

I hope you understand my question, if not let me know and I will try to explain further.
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: ResourceView: changing the selection style
Reply #1 - Jun 15th, 2009 at 6:19am
Print Post  
Hi,

Unfortunately there is currently no built-in way to achieve this selection behavior in Resource view. The only possibility would be to handle the Selection.Changed event and make programmatic changes to the selection so that it spans the clicked cells. Below is a sample code, which attempts to perform this task. This code however ignores properties such as UnitCount and HiddenDays and if you use them it might not work for you.

Code
Select All
void Selection_Changed(object sender, EventArgs e)
{
      List<DateTime> newRanges = new List<DateTime>();
      for (int i = 0; i < calendar1.Selection.Ranges.Count; i += 2)
      {
            DateTime d1 = calendar1.Selection.Ranges[i];
            DateTime d2 = calendar1.Selection.Ranges[i + 1];

            TimeUnit unit = calendar1.ResourceViewSettings.BottomTimelineSettings.Unit;
            if (unit == TimeUnit.Month)
            {
                  DateTime newD1 = new DateTime(d1.Year, d1.Month, 1);
                  if (d1 != newD1)
                  {
                        newRanges.Add(newD1);
                        newRanges.Add(d1);
                  }

                  DateTime newD2 = new DateTime(d2.Year, d2.Month, 1);
                  newD2 = newD2.AddMonths(1);
                  if (d2 != newD2)
                  {
                        newRanges.Add(d2);
                        newRanges.Add(newD2);
                  }
            }
            else if (unit == TimeUnit.Year)
            {
                  DateTime newD1 = new DateTime(d1.Year, 1, 1);
                  if (d1 != newD1)
                  {
                        newRanges.Add(newD1);
                        newRanges.Add(d1);
                  }

                  DateTime newD2 = new DateTime(d2.Year, 1, 1);
                  if (d2 != newD2)
                  {
                        newRanges.Add(d2);
                        newRanges.Add(newD2);
                  }
            }
            else
            {
                  long unitTicks = 0;
                  switch (unit)
                  {

                        case TimeUnit.Second:
                              unitTicks = TimeSpan.TicksPerSecond;
                              break;

                        case TimeUnit.Minute:
                              unitTicks = TimeSpan.TicksPerMinute;
                              break;

                        case TimeUnit.Hour:
                              unitTicks = TimeSpan.TicksPerHour;
                              break;

                        case TimeUnit.Day:
                              unitTicks = TimeSpan.TicksPerDay;
                              break;

                        case TimeUnit.Week:
                              unitTicks = TimeSpan.TicksPerDay * 7;
                              break;

                  }

                  if (d1.Ticks % unitTicks != 0)
                  {
                        DateTime newD1 = d1 - new TimeSpan(d1.Ticks % unitTicks);
                        newRanges.Add(newD1);
                        newRanges.Add(d1);
                  }

                  if (d2.Ticks % unitTicks != 0)
                  {
                        DateTime newD2 = d2 + new TimeSpan(unitTicks - d2.Ticks % unitTicks);
                        newRanges.Add(d2);
                        newRanges.Add(newD2);
                  }
            }
      }

      for (int j = 0; j < newRanges.Count; j += 2)
            calendar1.Selection.Add(newRanges[j], newRanges[j + 1]);
} 



Meppy
  
Back to top
 
IP Logged
 
ismar.slomic
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Jun 14th, 2009
Re: ResourceView: changing the selection style
Reply #2 - Jun 15th, 2009 at 8:22pm
Print Post  
Hi Meppy,
your code did exactly what I wanted it to do, thank you!!

Only thing I'm having problem with is that when I try to select the "Selection_Changed" method to the Selection.Changed event in the properties view of the Calendar, Visual Studio just ignores this action. And CalendarForm.Designer.cs is neither updated. I have successfully placed  following line of code to the Calendar.Designer.cs file:

Code
Select All
this.calendar.Selection.Changed += new EventHandler(Selection_Changed); 



the project builds fine, but when I open CalendarForm.cs (the Design view) I get following error:

Code
Select All
Unable to cast object of type 'MindFusion.Scheduling.WinForms.Selection' to type 'System.ComponentModel.IComponent' 



However, when I run the form, the selection style is the way I want it to be, but I would like to get rid of the error that is displayed in the Design view of the CalendarForm.
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: ResourceView: changing the selection style
Reply #3 - Jun 16th, 2009 at 5:47am
Print Post  
Move the line of code away from the InitializeComponent method and place it somewhere in your own code - for example, in the constructor of your form.

I hope this helps,
Meppy
  
Back to top
 
IP Logged
 
ismar.slomic
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Jun 14th, 2009
Re: ResourceView: changing the selection style
Reply #4 - Jun 18th, 2009 at 5:39am
Print Post  
Thanks, this helped!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint