Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic In resource view, Hightlight the selected row (Read 3064 times)
ironmonkey
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 3
Joined: Aug 29th, 2007
In resource view, Hightlight the selected row
Aug 29th, 2007 at 2:11pm
Print Post  
I need to hightlight the entire row when user selects an appointment or the resource, so he knows which row is being selected and can copy or swap the appointments. What method or property can achieve this ?
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: In resource view, Hightlight the selected row
Reply #1 - Aug 30th, 2007 at 5:47am
Print Post  
Try the following solution:

First, enable custom drawing of the resource row headers, by setting Calendar.CustomDraw to CustomDrawElements.ResourceViewRowHeader. Then handle the Calendar.Draw event. The event handler can have an implementation similar to the following:

Code
Select All
private void calendar_Draw(object sender, CustomDrawArgs e)
{
	if (e.Element == CustomDrawElements.ResourceViewRowHeader)
	{
		Contact contact = e.Resource as Contact;

		ItemCollection c = calendar.Schedule.GetAllItems(
			DateTime.MinValue, DateTime.MaxValue, contact);
		bool selected = false;
		foreach (Item i in c)
		{
			if (calendar.ItemSelection.Contains(i))
			{
				selected = true;
				break;
			}
		}

		if (selected)
		{
			Rectangle b = e.Bounds;
			b.Width -= 1;
			b.Height -= 1;
			e.Graphics.DrawRectangle(Pens.Red, b);
		}
	}
} 


The above code presumes that the resources in the calendar are contacts. If you are using different resources, perform the necessary modifications. The code draws a red border around the header of the resource row containing selected items. If you need some other kind of visualization, you may have to custom-draw another CustomDrawElements, such as ResourceViewCell.

Meppy
  
Back to top
 
IP Logged
 
madrider
YaBB Newbies
*
Offline



Posts: 15
Joined: Jul 30th, 2007
Re: In resource view, Hightlight the selected row
Reply #2 - Sep 4th, 2007 at 9:34pm
Print Post  
When I try that code, I get a null reference for contact and the count for c is 0. Why is that?

Contact contact = e.Resource as Contact;

Resource is a valid object but contact is null.
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: In resource view, Hightlight the selected row
Reply #3 - Sep 5th, 2007 at 6:25am
Print Post  
This can happen if you are not grouping by contacts (e.g. you are grouping by locations or general resources). In this case you will have to cast to the appropriate type. For example, if you are grouping by location, you will have to modify the code in the following way:

Code
Select All
Location location = e.Resource as Location; 


Meppy
  
Back to top
 
IP Logged
 
ironmonkey
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 3
Joined: Aug 29th, 2007
Re: In resource view, Hightlight the selected row
Reply #4 - Sep 7th, 2007 at 9:23pm
Print Post  
Hi, Meppy:
I had another issue in Resource view, for a resource if he has request time off, I need to show the time period ( like from 8AM to 4PM), but user still can add appointment( schedule ) during that period. How can I just paint the background as red?
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: In resource view, Hightlight the selected row
Reply #5 - Sep 10th, 2007 at 5:12am
Print Post  
You can use a similar approach. You need to set CustomDrawElements.ResourceViewCell as a value of the Calendar.CustomDraw property and modify the contents of the Calendar.Draw event handler in a way similar to the following:

Code
Select All
if (e.Element == CustomDrawElements.ResourceViewCell)
{
	Contact contact = e.Resource as Contact;

	if (e.Date.TimeOfDay.Hours >= 8 &&
		e.Date.TimeOfDay.Hours <= 16)
	{
		Rectangle b = e.Bounds;
		b.X += 1;
		b.Width -= 1;
		b.Height -= 1;

		Brush brush = new SolidBrush(Color.FromArgb(200, Color.Red));
		e.Graphics.FillRectangle(brush, b);
		brush.Dispose();
	}
} 


Hope this helps.

Meppy
  
Back to top
 
IP Logged
 
ironmonkey
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 3
Joined: Aug 29th, 2007
Re: In resource view, Hightlight the selected row
Reply #6 - Sep 11th, 2007 at 3:59pm
Print Post  
It works. Thanks!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint